* {
    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: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    /* 移动端优化 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: pan-y;
    overscroll-behavior: none;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    height: 90vh;
    max-height: 800px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    text-align: center;
}

.chat-header h1 {
    font-size: 24px;
    margin-bottom: 5px;
}

.chat-header p {
    font-size: 14px;
    opacity: 0.9;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #f5f5f5;
    /* 移动端优化 */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.message {
    display: flex;
    animation: fadeIn 0.3s ease-in;
}

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

.message-content {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
}

/* Markdown 样式 */
.bot-message .message-content {
    text-align: left;
}

.bot-message .message-content h1,
.bot-message .message-content h2,
.bot-message .message-content h3,
.bot-message .message-content h4,
.bot-message .message-content h5,
.bot-message .message-content h6 {
    margin-top: 16px;
    margin-bottom: 8px;
    font-weight: 600;
}

.bot-message .message-content h1 { font-size: 1.5em; }
.bot-message .message-content h2 { font-size: 1.3em; }
.bot-message .message-content h3 { font-size: 1.1em; }

.bot-message .message-content p {
    margin: 8px 0;
}

.bot-message .message-content ul,
.bot-message .message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.bot-message .message-content li {
    margin: 4px 0;
}

/* 代码块样式 */
.bot-message .message-content pre {
    background: #f6f8fa;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.bot-message .message-content code {
    background: #f6f8fa;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco' ,'Courier New', Courier, monospace;
    font-size: 0.9em;
}

.bot-message .message-content pre code {
    background: transparent;
    padding: 0;
}

/* 表格样式 */
.bot-message .message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.bot-message .message-content th,
.bot-message .message-content td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.bot-message .message-content th {
    background: #f6f8fa;
    font-weight: 600;
}

/* 引用样式 */
.bot-message .message-content blockquote {
    border-left: 4px solid #667eea;
    margin: 8px 0;
    padding-left: 12px;
    color: #666;
}

/* 链接样式 */
.bot-message .message-content a {
    color: #667eea;
    text-decoration: none;
}

.bot-message .message-content a:hover {
    text-decoration: underline;
}

/* LaTeX 数学公式样式 */
.bot-message .message-content .katex {
    font-size: 1.1em;
}

.bot-message .message-content .katex-display {
    margin: 12px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* 水平分隔线 */
.bot-message .message-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 12px 0;
}

/* 图片样式 */
.bot-message .message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}

.user-message {
    justify-content: flex-end;
}

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

.bot-message .message-content {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.error-message .message-content {
    background: #fee;
    color: #c33;
}

.chat-input-container {
    display: flex;
    padding: 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 12px 15px;
    font-size: 15px;
    resize: none;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s;
    min-height: 44px;
    max-height: 150px;
    /* 移动端优化 */
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

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

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

.send-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.3s;
    flex-shrink: 0;
    /* 移动端优化 */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.05);
}

.send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading-indicator {
    display: none;
    padding: 10px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    justify-content: center;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

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

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* 响应式设计 */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .chat-container {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }

    /* 优化头部 */
    .chat-header {
        padding: 16px;
    }

    .chat-header h1 {
        font-size: 18px;
        margin-bottom: 4px;
    }

    .chat-header p {
        font-size: 12px;
    }

    /* 优化消息区域 */
    .chat-messages {
        padding: 12px;
        gap: 12px;
    }

    .message-content {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 15px;
    }

    /* 优化 Markdown 元素 */
    .bot-message .message-content h1 { font-size: 1.3em; }
    .bot-message .message-content h2 { font-size: 1.2em; }
    .bot-message .message-content h3 { font-size: 1.1em; }

    .bot-message .message-content p {
        margin: 6px 0;
    }

    /* 优化代码块 */
    .bot-message .message-content pre {
        padding: 10px;
        margin: 6px 0;
        font-size: 13px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .bot-message .message-content code {
        font-size: 13px;
        padding: 2px 4px;
    }

    /* 优化表格 - 移动端横向滚动 */
    .bot-message .message-content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        font-size: 14px;
    }

    .bot-message .message-content th,
    .bot-message .message-content td {
        padding: 6px 8px;
        font-size: 13px;
    }

    /* 优化列表 */
    .bot-message .message-content ul,
    .bot-message .message-content ol {
        padding-left: 20px;
        margin: 6px 0;
    }

    .bot-message .message-content li {
        margin: 3px 0;
    }

    /* 优化引用 */
    .bot-message .message-content blockquote {
        padding-left: 10px;
        margin: 6px 0;
        font-size: 14px;
    }

    /* 优化数学公式 */
    .bot-message .message-content .katex {
        font-size: 1em;
    }

    .bot-message .message-content .katex-display {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 10px 0;
    }

    /* 优化输入区域 */
    .chat-input-container {
        padding: 12px;
        gap: 8px;
    }

    .chat-input {
        padding: 10px 12px;
        font-size: 16px; /* iOS 上防止自动缩放 */
        border-radius: 10px;
        min-height: 40px;
        max-height: 120px;
    }

    .send-button {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        flex-shrink: 0;
    }

    .send-button svg {
        width: 20px;
        height: 20px;
    }

    /* 优化加载指示器 */
    .loading-indicator {
        padding: 8px 12px;
    }

    /* 优化滚动条（移动端隐藏） */
    .chat-messages::-webkit-scrollbar {
        width: 0;
        display: none;
    }

    /* 确保代码块可以横向滚动 */
    .bot-message .message-content pre code {
        display: block;
        overflow-x: auto;
    }
}

/* 小屏幕优化 (< 480px) */
@media (max-width: 480px) {
    .chat-header h1 {
        font-size: 16px;
    }

    .chat-header p {
        font-size: 11px;
    }

    .chat-messages {
        padding: 10px;
        gap: 10px;
    }

    .message-content {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 14px;
    }

    .bot-message .message-content pre {
        padding: 8px;
        font-size: 12px;
    }

    .bot-message .message-content code {
        font-size: 12px;
    }

    .chat-input-container {
        padding: 10px;
    }

    .chat-input {
        padding: 8px 10px;
        font-size: 16px;
    }
}

/* 横屏模式优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-container {
        height: 100vh;
    }

    .chat-header {
        padding: 10px;
    }

    .chat-header h1 {
        font-size: 16px;
    }

    .chat-header p {
        display: none; /* 横屏隐藏副标题节省空间 */
    }

    .chat-messages {
        padding: 10px;
    }

    .chat-input-container {
        padding: 10px;
    }
}

/* 优化触摸体验 */
@media (hover: none) and (pointer: coarse) {
    .send-button:active {
        transform: scale(0.92);
        opacity: 0.8;
    }

    /* 增加点击区域 */
    .send-button {
        min-width: 44px;
        min-height: 44px;
    }
}


