/* 添加CSS变量支持 */
:root {
    --bg-opacity: 0;
    --bg-blur: 0px;
    --text-color: #333;
    --bg-color: #f6f6f6;
    --primary-color: #f34c44;
    --secondary-color: #f1f1f1;
    --accent-color: #c91818;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

body {
    background-color: #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.app-container {
    display: flex;
    width: 100%;
    max-width: 1200px;
    height: 90vh;
    position: relative;
}

/* 遮罩层样式 */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}

/* 侧边栏样式 */
.sidebar {
    width: 280px;
    min-width: 280px; /* 防止缩小 */
    background-color: #fff;
    border-radius: 10px 0 0 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
    height: 100%; /* 确保高度与父容器一致 */
}

.sidebar-header {
    padding: 15px;
    background-color: #f8f8f8;
    border-bottom: 1px solid #eaeaea;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 500;
    color: #333;
}

.new-chat-btn {
    background-color: transparent;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
    z-index: 2;
    margin-left: auto;
}

.new-chat-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    padding: 12px;
    background-color: #f9f9f9;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

.history-item:hover {
    background-color: #f0f0f0;
}

.history-item.active {
    background-color: #e3f2fd;
    border-left: 3px solid #f34c44;
}

.history-item .item-content {
    flex: 1;
    overflow: hidden;
}

.history-item .title {
    font-size: 14px;
    color: #333;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item .date {
    font-size: 12px;
    color: #888;
}

.history-item .delete-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    margin-left: 8px;
}

.history-item .delete-btn:hover {
    background-color: #ff6b6b;
    color: white;
}

/* 移动端侧边栏切换按钮 */
.toggle-sidebar-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    position: relative;
    z-index: 2;
    margin-right: auto;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    height: 90vh;
    background-color: #f6f6f6;
    border-radius: 0 10px 10px 0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
}

.chat-header {
    background-color: var(--primary-color);
    color: white;
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* 为标题背景添加祥云纹装饰 */
.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('../images/cloud.svg');
    background-repeat: repeat;
    background-size: auto 800%;
    background-position: center;
    opacity: 1;
    z-index: 0;
}

.chat-header h1 {
    font-size: 1.5rem;
    font-weight: 500;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    text-align: center;
    z-index: 1;
}

.chat-messages {
    flex: 1;
    height: 100%;
    width: 100%;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-image: url('../images/111.gif');
    background-repeat: no-repeat;
    background-size: 60%;
    background-position: center bottom 0px;
    position: relative;
}

.chat-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(252, 252, 252, var(--bg-opacity));
    backdrop-filter: blur(var(--bg-blur));
    z-index: 0;
}

.message {
    display: flex;
    margin-bottom: 10px;
    max-width: 85%;
    position: relative;
    z-index: 1;
}

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

.message.assistant {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    max-width: 90%;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1.5;
    word-break: break-word;
}

/* 添加Markdown渲染样式 */
.message-content.markdown {
    padding: 15px 18px;
}

.message-content.markdown h1,
.message-content.markdown h2,
.message-content.markdown h3,
.message-content.markdown h4,
.message-content.markdown h5,
.message-content.markdown h6 {
    margin-top: 20px;
    margin-bottom: 12px;
    font-weight: 600;
    line-height: 1.25;
}

.message-content.markdown h1 {
    font-size: 1.5em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
}

.message-content.markdown h2 {
    font-size: 1.3em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
}

.message-content.markdown h3 {
    font-size: 1.1em;
}

.message-content.markdown p {
    margin-top: 8px;
    margin-bottom: 8px;
}

.message-content.markdown ul, 
.message-content.markdown ol {
    margin-top: 8px;
    margin-bottom: 8px;
    padding-left: 25px;
}

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

.message-content.markdown code {
    font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
    background-color: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

.message-content.markdown pre {
    background-color: #f6f8fa;
    border-radius: 6px;
    padding: 12px;
    margin: 10px 0;
    overflow: auto;
    max-width: 100%;
}

.message-content.markdown pre code {
    background-color: transparent;
    padding: 0;
    white-space: pre;
    display: block;
    overflow-x: auto;
    font-size: 0.9em;
    line-height: 1.45;
}

.message-content.markdown blockquote {
    margin: 10px 0;
    padding: 0 1em;
    color: #656d76;
    border-left: 3px solid #d0d7de;
}

.message-content.markdown img {
    max-width: 100%;
    height: auto;
    margin: 10px 0;
    border-radius: 6px;
}

.message-content.markdown table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
}

.message-content.markdown table th,
.message-content.markdown table td {
    padding: 6px 13px;
    border: 1px solid #d0d7de;
}

.message-content.markdown table tr {
    background-color: #ffffff;
    border-top: 1px solid #d0d7de;
}

.message-content.markdown table tr:nth-child(2n) {
    background-color: #f6f8fa;
}

/* 代码复制按钮样式 */
.code-toolbar {
    position: relative;
}

.copy-button {
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 3px 8px;
    font-size: 12px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
    opacity: 0.7;
}

.copy-button:hover {
    opacity: 1;
}

.user .message-content {
    background-color: #f34c44;
    color: white;
    border-bottom-right-radius: 5px;
}

.assistant .message-content {
    background-color: #f1f1f1;
    color: #333;
    border-bottom-left-radius: 5px;
}

.system .message-content {
    background-color: #f8f8f8;
    color: #666;
    font-style: italic;
    text-align: center;
}

.loading-dots {
    display: inline-block;
}

.loading-dots::after {
    content: '...';
    animation: dots 1.5s infinite;
    display: inline-block;
    width: 20px;
    text-align: left;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

.chat-input-container {
    padding: 15px;
    background-color: #f9f9f9;
    display: flex;
    gap: 10px;
    border-top: 1px solid #eaeaea;
}

#message-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    resize: none;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

#message-input:focus {
    border-color: #f34c44;
}

#send-btn {
    padding: 0 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

#send-btn:hover {
    background-color: var(--accent-color);
}

#send-btn:disabled {
    background-color: #ff9090;
    cursor: not-allowed;
}

/* 添加处理状态样式 */
.processing-status {
    font-style: italic;
    color: #666;
    padding: 5px;
    font-size: 14px;
    display: flex;
    align-items: center;
}

.processing-status::after {
    content: '';
    width: 12px;
    height: 12px;
    margin-left: 8px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: pulse 1.5s infinite;
    display: inline-block;
}

/* 添加光标闪烁效果 */
.processing-status::before {
    content: '|';
    color: var(--primary-color);
    margin-right: 5px;
    animation: cursor-blink 1s infinite;
    font-weight: bold;
}

/* 等待光标样式 - 模型输出前的闪烁光标 */
.waiting-cursor {
    position: relative;
    height: 24px;
    padding: 5px;
    display: flex;
    align-items: center;
    color: #666;
    font-style: italic;
}

.waiting-cursor::before {
    content: '|';
    color: var(--primary-color);
    font-size: 20px;
    font-weight: bold;
    animation: cursor-blink 1s infinite;
    margin-right: 8px;
}

.waiting-cursor::after {
    content: '正在推演中';
    font-size: 14px;
}

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

@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(0.8);
        opacity: 0.8;
    }
}

/* 适配移动设备 */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
    }
    
    .chat-container {
        height: 100vh;
        border-radius: 0;
    }
    
    body {
        padding: 0;
    }
    
    .message {
        max-width: 90%;
    }
    
    .sidebar {
        position: fixed; /* 改用fixed以确保覆盖整个页面 */
        top: 0;
        left: 0;
        height: 100vh; /* 使用视口高度 */
        transform: translateX(-100%);
        border-radius: 0;
        transition: transform 0.3s ease;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .toggle-sidebar-btn {
        display: flex;
    }
    
    .new-chat-btn {
        padding: 5px 10px;
        font-size: 12px;
        background-color: transparent; /* 移除背景色 */
        box-shadow: none; /* 移除阴影 */
    }
    
    .new-chat-btn:hover {
        background-color: transparent; /* 移除悬停时的背景色 */
    }
    
    .chat-header h1 {
        font-size: 1.2rem;
    }
    
    /* 移动设备上保持背景图大小为80% */
    .chat-messages {
        background-size: 80%;
    }
}