:root {
    --primary-color: #07C160;
    --secondary-color: #F7F7F7;
    --text-color: #333;
    --light-text: #999;
    --border-color: #eaeaea;
    --user-bubble: #95EC69;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    color: var(--text-color);
    line-height: 1.5;
}

.container {
    max-width: 500px;
    margin: 20px auto;
    background-color: white;
    box-shadow: var(--shadow);
    border-radius: 12px;
    overflow: hidden;
    height: 90vh;
    display: flex;
    flex-direction: column;
}

.header {
    padding: 15px 20px;
    background-color: var(--primary-color);
    color: white;
    text-align: center;
}

.header h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 500;
}

.header i {
    margin-right: 8px;
}

.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: var(--secondary-color);
    /* 新增关键属性 */
    min-height: 0; /* 修复flex容器滚动问题 */
    transform: translateZ(0); /* 触发GPU加速 */
    will-change: transform; /* 优化渲染性能 */
    overflow-anchor: auto; /* 改善滚动行为 */
}

.message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 80%;  /* 保持最大宽度限制 */
    min-width: 40px; /* 设置最小宽度 */
    word-wrap: break-word;
    position: relative;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
    background-color: var(--message-bg, #fff);
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    width: fit-content; /* 关键属性：宽度根据内容自适应 */
     transition: width 0.2s ease, height 0.2s ease;
}

/* 确保动画正确定义 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.assistant-message {
    --message-bg: var(--assistant-message-color, #f1f1f1);
    margin-right: auto;
}
.user-message .text {
    white-space: pre-wrap; /* 保持换行但允许文本换行 */
    display: inline-block; /* 让文本容器根据内容调整 */
}

/* 修复可能的flex容器问题 */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh; /* 必须设定明确高度 */
    overflow: hidden; /* 防止外层滚动 */
}

/* 加载状态指示器 */
.loading-indicator {
    position: sticky;
    bottom: 0;
    background: var(--secondary-color);
    padding: 10px;
    text-align: center;
    z-index: 10;
}

.user-message {
    --message-bg: var(--user-bubble);
    margin-left: auto;
    margin-right: 10px;
    border-bottom-right-radius: 5px;
    /* 移除固定宽度设置，使用fit-content */
    width: -moz-fit-content; /* Firefox兼容 */
    width: fit-content;
    max-width: 80%; /* 仍然保持最大宽度限制 */
}

.assistant-message {
    --message-bg: white;
    margin-right: auto;
    border-bottom-left-radius: 5px;
    box-shadow: var(--shadow);
    width: -moz-fit-content;
    width: fit-content;
    max-width: 80%;
}

.time {
    font-size: 11px;
    color: var(--light-text);
    margin-top: 5px;
    text-align: right;
}

.input-area {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background-color: white;
    position: relative;
}

.input-area.drag-over {
    background-color: rgba(7, 193, 96, 0.1);
    border: 2px dashed var(--primary-color);
}

.message-input {
    position: relative;
    margin-bottom: 10px;
}

textarea {
    width: 100%;
    height: 80px;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border 0.2s;
}

textarea:focus {
    border-color: var(--primary-color);
}

.file-hint {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.9);
    color: var(--primary-color);
    font-size: 14px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    border: 2px dashed var(--primary-color);
}

.file-hint i {
    margin-right: 8px;
    font-size: 20px;
}

.drag-over .file-hint {
    opacity: 1;
}

.action-buttons {
    display: flex;
    gap: 10px;
}

.file-button, .send-button {
    padding: 10px 15px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.file-button {
    background-color: white;
    color: var(--primary-color);
    border: 1px solid var(--border-color);
}

.file-button:hover {
    background-color: var(--secondary-color);
}

.send-button {
    background-color: var(--primary-color);
    color: white;
    flex: 1;
    justify-content: center;
}

.send-button:hover {
    background-color: #06AD56;
}

.send-button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.file {
    margin-top: 10px;
}

.file img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    display: block;
    margin-top: 5px;
}

.file a {
    color: var(--primary-color);
    text-decoration: none;
    display: inline-block;
    margin-top: 5px;
    padding: 5px 10px;
    background-color: var(--secondary-color);
    border-radius: 4px;
}

.file a:hover {
    text-decoration: underline;
}

.no-messages {
    text-align: center;
    color: var(--light-text);
    padding: 40px 20px;
}

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

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

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

::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}


.message.visible {
    opacity: 1;
    transform: translateY(0);
}