.main-chat { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; overflow: hidden; }

.chat-header {
    display: flex; justify-content: space-between; align-items: center; padding: 16px 40px;
    background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border); z-index: 5; flex-shrink: 0;
}
.chat-header h3 { font-size: 16px; font-weight: 600; text-align: center; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 20px; }
.clear-chat-btn {
    background: transparent; border: 1px solid #ccc; padding: 6px 12px; border-radius: 6px; cursor: pointer;
    font-size: 12px; transition: var(--transition); display: flex; align-items: center; gap: 6px; font-weight: 500;
}
.clear-chat-btn:hover { background: #eee; border-color: #000; }
.clear-chat-btn svg { width: 14px; height: 14px; fill: currentColor; }

.chat-messages {
    flex: 1 1 auto; min-height: 0; padding: 40px 88px 40px 40px; overflow-y: auto; scroll-behavior: smooth;
    display: flex; flex-direction: column; gap: 24px;
    position: relative; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}

.scroll-bottom-btn {
    position: absolute;
    top: 50%;
    right: 18px;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 10;
}
.scroll-bottom-btn.show {
    opacity: 1;
    visibility: visible;
}
.scroll-bottom-btn:hover {
    background: #f5f5f5;
    transform: translateY(calc(-50% - 2px));
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}
.scroll-bottom-btn svg {
    width: 20px;
    height: 20px;
    fill: #666;
}

.message-wrapper { position: relative; display: flex; flex-direction: column; max-width: 80%; animation: slideUpFade 0.4s forwards; }
.message-wrapper.user { align-self: flex-end; align-items: flex-end; }
.message-wrapper.bot { align-self: flex-start; align-items: flex-start; }

.message { padding: 16px 20px; border-radius: var(--radius-lg); font-size: 15px; line-height: 1.6; word-wrap: break-word; width: 100%; overflow: hidden; min-width: 0; }

.message.user { background-color: var(--message-user-bg); color: var(--message-user-text); border-bottom-right-radius: 4px; }
.message.bot { background-color: var(--message-bot-bg); color: var(--message-bot-text); border-bottom-left-radius: 4px; border: 1px solid var(--glass-border); box-shadow: 0 4px 12px rgba(0,0,0,0.03); }
.message img { max-width: 100%; border-radius: 8px; margin-bottom: 10px; border: 1px solid rgba(255,255,255,0.2); }

.message-actions { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity 0.2s; }
.message-wrapper:hover .message-actions { opacity: 1; }
.action-icon {
    width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: pointer; color: #888; transition: all 0.2s;
}
.action-icon:hover { background: #eee; border-color: #ddd; color: #000; }
.action-icon svg { width: 14px; height: 14px; fill: currentColor; }

.edit-area { width: 100%; min-width: 400px; min-height: 100px; padding: 12px; border: 1px solid #000; border-radius: var(--radius-md); font-family: inherit; font-size: 14px; resize: vertical; margin-bottom: 10px; outline: none; background: #fff; line-height: 1.5; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.edit-actions { display: flex; gap: 10px; justify-content: flex-end; width: 100%; }


.markdown-body { font-family: inherit; }
.markdown-body .DOMD-Root { --domd-base-100: transparent; --domd-base-200: rgba(0,0,0,0.04); --domd-base-300: rgba(0,0,0,0.08); --domd-base-content: currentColor; --domd-font-size-base: 1em; color: inherit; }
.markdown-body .DOMD-Root > :first-child { padding-top: 0; margin-top: 0; }
.markdown-body .DOMD-Root > :last-child { margin-bottom: 0; padding-bottom: 0; }
.markdown-body p { margin-bottom: 1em; } .markdown-body p:last-child { margin-bottom: 0; }
.markdown-body code { background-color: rgba(128,128,128,0.15); padding: 2px 4px; border-radius: 4px; font-family: "Sarasa Gothic Fixed", "Sarasa Fixed SC", "Sarasa Fixed TC", monospace; font-size: 0.9em; }
.message.user .markdown-body code { background-color: rgba(255,255,255,0.2); }
.markdown-body pre { background-color: #282c34; padding: 12px; border-radius: 8px; overflow-x: auto; overflow-wrap: break-word; word-break: break-all; margin: 1em 0; border: 1px solid #333; max-width: 100%; }
.markdown-body pre code { background-color: transparent; padding: 0; color: #abb2bf; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; font-family: "Sarasa Gothic Fixed", "Sarasa Fixed SC", "Sarasa Fixed TC", monospace; }

.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin: 0.5em 0; }
.markdown-body ul { list-style-type: disc; }
.markdown-body ol { list-style-type: decimal; }
.markdown-body li { margin-bottom: 0.25em; }
.markdown-body li > ul, .markdown-body li > ol { margin: 0.25em 0; }

.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-body th, .markdown-body td { border: 1px solid #ddd; padding: 8px 12px; text-align: left; }
.message.user .markdown-body th, .message.user .markdown-body td { border-color: #444; }

.loading {
    align-self: flex-start; color: var(--text-secondary); font-size: 13px;
    padding: 10px 20px; display: none; font-style: italic; opacity: 0; animation: fadeIn 0.3s forwards;
}
.loading span::after { content: '.'; animation: dots 1.5s steps(4, end) infinite; }

.stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: #000;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursorBlink 0.8s step-end infinite;
    border-radius: 1px;
}
