body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
    height: 100dvh;
    overflow: hidden;
}

@supports not (height: 100dvh) {
    body {
        height: 100vh;
    }
}

/* 导航栏样式 */
.nav-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 0.5rem 1rem;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: #374151;
    position: relative;
    cursor: pointer;
}

.nav-items {
    display: flex;
    gap: 1rem;
}

.nav-button {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    background-color: #f3f4f6;
    color: #374151;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-button:hover {
    background-color: #e5e7eb;
}

.nav-button.active {
    background-color: #3b82f6;
    color: white;
}

/* 重新设计聊天容器样式 - 全屏风格 */
#chat-container {
    position: fixed;
    top: 56px; /* 导航栏高度 */
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(100dvh - 56px);
    background: #f9fafc;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    display: none;
    flex-direction: column;
    overflow: hidden;
    margin: 0 auto; /* 水平居中 */
}

@supports not (height: 100dvh) {
    #chat-container {
        /*
         * 回退到原有的 100vh 方案
         * 若有需要可做额外针对性调整
         */
        height: calc(100vh - 56px);
    }
}

/* 聊天头部样式 */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background-color: #ffffff;
    border-bottom: 1px solid #f0f0f0;
    z-index: 10;
}

.chat-header span {
    font-weight: 600;
    color: #333;
    font-size: 16px;
    letter-spacing: 0.5px;
}

/* 清除按钮样式 */
.clear-btn {
    background: transparent;
    color: #64748b;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-btn:hover {
    background: #f1f5f9;
    color: #ef4444;
    transform: none;
}

.clear-btn svg {
    width: 16px;
    height: 16px;
}

/* 消息容器 - 占满中间区域 */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 80px; /* 增加底部边距，防止输入框遮挡 */
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
    background: #f9fafc;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
    display: flex;
    flex-direction: column; /* 确保消息垂直排列 */
    align-items: stretch; /* 消息宽度自适应 */
}

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

#messages::-webkit-scrollbar-track {
    background: transparent;
}

#messages::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 10px;
}

/* 消息样式优化 */
.message {
    padding: 12px 16px;
    border-radius: 12px;
    margin: 8px 0; /* 确保垂直间距 */
    max-width: 85%;
    line-height: 1.5;
    position: relative;
    word-break: break-word;
    animation: message-appear 0.3s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: flex; /* 改回flex布局 */
    align-items: flex-start;
    width: fit-content; /* 宽度适应内容 */
}

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

/* 消息气泡样式 */
.user-message {
    background: linear-gradient(135deg, #9683EC, #8A75E3);
    color: white;
    align-self: flex-end; /* 右对齐 */
    margin-left: auto; /* 推到右边 */
    margin-right: 0;
    border-bottom-right-radius: 4px;
    text-align: left; /* 文本左对齐 */
    display: flex; /* 保持为flex布局 */
}

.ai-message {
    background: linear-gradient(135deg, #7BC6FF, #64B5F6);
    color: white;
    align-self: flex-start; /* 左对齐 */
    margin-right: auto; /* 推到左边 */
    margin-left: 0;
    border-bottom-left-radius: 4px;
    text-align: left; /* 文本左对齐 */
    display: flex; /* 保持为flex布局 */
}

/* 消息内容样式 */
.message-content {
    flex-grow: 1; /* 允许内容增长 */
    word-break: break-word;
    font-size: 15px;
    white-space: normal; /* 确保文本正常换行 */
    width: 100%; /* 占据所有可用空间 */
}

/* 消息中代码块样式 */
.message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

/* 删除按钮样式改进 */
.message-delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: all 0.2s;
    transform: scale(0.8);
    cursor: pointer;
    z-index: 5;
}

.user-message .message-delete-btn,
.ai-message .message-delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: all 0.2s;
    transform: scale(0.8);
    cursor: pointer;
    z-index: 5;
}

.user-message:hover .message-delete-btn,
.ai-message:hover .message-delete-btn {
    opacity: 1;
    transform: scale(1);
}

.message-delete-btn:hover {
    background: rgba(239, 68, 68, 0.9);
    transform: scale(1.1);
}

/* 输入区域置底固定 - 修正边框圆角和位置 */
#input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.8); /* 半透明背景 */
    backdrop-filter: blur(10px); /* 高斯模糊效果 */
    -webkit-backdrop-filter: blur(10px); /* Safari 浏览器支持 */
    border-top: 1px solid rgba(240, 240, 240, 0.7);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.03);
    z-index: 100;
    max-width: 900px;
    margin: 0 auto;
    left: 50%;
    transform: translateX(-50%);
    box-sizing: border-box;
    border-radius: 20px; /* 修改：改为四周都有圆角 */
    margin-bottom: 10px; /* 添加：距离底部有一定间距，显示底部圆角 */
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#input-container:hover,
#input-container:focus-within {
    box-shadow: 0 -2px 15px rgba(0,0,0,0.06);
    transform: translateX(-50%) translateY(-2px);
}

input {
    flex-grow: 1;
    padding: 14px 18px;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    transition: all 0.2s;
    font-size: 15px;
    background: #f8fafc;
    max-width: 700px; /* 限制最大宽度 */
    margin: 0 auto; /* 水平居中 */
}

input:focus {
    outline: none;
    border-color: #9683EC;
    background: white;
    box-shadow: 0 0 0 3px rgba(150, 131, 236, 0.1);
}

/* 强化输入框样式 */
#user-input {
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    width: calc(100% - 60px); /* 减去发送按钮宽度和间距 */
    background: rgba(248, 250, 252, 0.7); /* 半透明背景 */
    border: 1px solid rgba(226, 232, 240, 0.8);
    transition: all 0.3s ease;
}

#user-input:focus {
    box-shadow: 0 2px 15px rgba(150, 131, 236, 0.15);
    border-color: #9683EC;
    background: rgba(255, 255, 255, 0.9); /* 聚焦时背景更不透明 */
}

button {
    background: #9683EC;
    padding: 10px 20px;
    border-radius: 24px;
    font-weight: 500;
    transition: all 0.2s;
    border: none;
    color: white;
    cursor: pointer;
}

button:hover {
    background: #8A75E3;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* 发送按钮样式优化 */
.send-btn {
    min-width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: #9683EC;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.send-btn:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* 增加消息时间戳样式 */
.message-timestamp {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 5px;
    text-align: right;
}

/* 消息头像样式 */
.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    margin-right: 8px;
    flex-shrink: 0;
}

/* 文本域样式 */
textarea {
    width: 100%;
    height: 100px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    resize: none;
}

/* 设置容器全屏样式 - 修正居中问题 */
#config-container {
    position: fixed;
    top: 56px; /* 导航栏高度 */
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(100dvh - 56px);
    width: 100%;
    background: rgba(249, 250, 252, 0.95);
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
    display: none;
    flex-direction: column; /* 改为纵向排列 */
    align-items: center;
    justify-content: center; /* 完全居中 */
    z-index: 999; /* 确保层级正确 */
}

/* 设置容器内部滚动区域 - 修正水平对齐问题 */
.settings-container {
    max-width: 600px;
    width: 100%;
    max-height: 80vh; /* 限制最大高度 */
    overflow-y: auto;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
    margin: 0 auto; /* 确保水平居中 */
}

#config-container h3 {
    margin-top: 10px;
    margin-bottom: 20px;
    color: #333;
    text-align: center;
    font-size: 1.5em;
}

/* 设置容器内部滚动区域 */
.settings-container {
    max-width: 600px;
    width: 100%;
    max-height: 80vh; /* 限制最大高度 */
    overflow-y: auto;
    padding: 15px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

/* 修改设置容器的内容样式 */
.settings-container .settings-section {
    width: 100%;
    margin-bottom: 15px;
}

/* 修改设置底部按钮容器样式 */
.settings-footer {
    max-width: 600px;
    width: 100%;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
}

/* 确保Live2D看板娘不会被聊天窗口遮挡 */
#waifu {
    z-index: 1001 !important;
}

/* 适配小屏幕 */
@media (max-width: 768px) {
    #messages {
        padding: 15px 10px;
        padding-bottom: 100px; /* 增加底部间距，为输入框留出空间 */
    }
    
    .message {
        max-width: 95%;
        padding: 10px 12px;
    }
    
    #input-container {
        padding: 10px;
        bottom: 10px; /* 修改：不再紧贴底部，留出间距显示圆角 */
        border-radius: 18px; /* 适当调小圆角 */
    }
    
    #user-input {
        padding: 10px 15px;
    }
    
    .send-btn {
        min-width: 42px;
        height: 42px;
    }
}

/* 针对特小屏幕的进一步优化 */
@media (max-width: 576px) {
    #input-container {
        bottom: 60px; /* 调整：大幅增加距离底部的间距，防止被遮挡 */
        padding: 8px 12px;
        border-radius: 16px;
        width: 94%; /* 略微增加宽度让输入框更容易看到 */
        max-width: 94%;
        z-index: 1050; /* 确保输入框在看板娘之上 */
        margin-bottom: 0px; /* 增加底部外边距 */
    }
    
    #messages {
        padding-bottom: 220px; /* 增加底部内边距，确保内容不被输入框遮挡 */
    }
    
    /* 添加iOS底部安全区域适配 */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        #input-container {
            padding-bottom: calc(8px + env(safe-area-inset-bottom));
            bottom: calc(60px + env(safe-area-inset-bottom)); /* 同时考虑安全区域 */
        }
    }
    
    /* 修复iPhone Safari底部工具栏问题 */
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* 为不同设备优化Live2D位置 */
@media (max-width: 576px) {
  #waifu {
    /* 不要隐藏看板娘，只调整位置 */
    bottom: 220px !important; /* 提高位置，确保不挡住输入框 */
    right: 0 !important;
    transform: scale(0.8); /* 稍微缩小看板娘尺寸 */
    transform-origin: bottom right;
  }
}

/* 确认对话框样式 - 修复位置问题 */
.confirm-dialog {
    /* 移除现有样式，在JS中直接设置内联样式 */
}

/* 移除可能干扰的样式 */
.confirm-dialog > div {
    /* 移除现有样式，在JS中直接设置内联样式 */
}

/* 删除确认对话框按钮样式，改为内联样式 */
.confirm-dialog-buttons,
.confirm-dialog-cancel,
.confirm-dialog-confirm {
    /* 移除现有样式，在JS中直接设置内联样式 */
}
