/* ai-chat.css */
#chat-widget-wrapper {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10001; /* Ensure the chat widget is above other content */
    width: 60vw;
    height: 80vh;
    min-width: 300px;
    min-height: 400px;
    resize: both;
}

#chat-widget-wrapper::after {
    display: none;
}

.chat-widget {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(11, 126, 157, 0.2);
    display: flex;
    flex-direction: column;
    font-size: 14px;
    overflow: hidden;
    background-color: #FFF;
}

#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #0B7E9D;
    color: #F9F6E5;
    cursor: move;
}

#chat-form-title {
    /* Ignore all mouse events */
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none; /* For Safari */
    -moz-user-select: none; /* For Firefox */
    -ms-user-select: none; /* For IE */
}

#chat-close-button {
    position: absolute;
    right: 10px;
    font-size: 24px;
    margin-top: auto;
    background-color: #0B7E9D;
    color: #F9F6E5;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-area {
    flex-grow: 1;
    border: 1px solid #ccc;
    overflow-y: auto;
    padding: 10px;
}

.chat-input-area {
    position: relative; /* 确保层级正确 */
    padding: 10px;
    background-color: #FFF;
}

.chat-input-wrapper {
    display: flex;
    flex-direction: column;
    border: 1px solid #0B7E9D;
    border-radius: 20px;
    overflow: hidden;
}

.chat-textarea-container {
    padding: 10px 10px 0 10px;
}

#chat-user-input {
    width: 100%;
    height: 20px; /* 1 line */
    max-height: 120px; /* ~6 lines */
    padding: 0;
    border: none;
    box-shadow: none;
    font-size: 14px;
    line-height: 20px;
    resize: none;
    overflow-y: auto;
    box-sizing: border-box;
    background: transparent;
}

#chat-user-input:focus {
    outline: none;
}

.chat-bottom-controls {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 5px 10px;
    background: transparent;
}

#chat-knowledge-base, #chat-summary-button {
    padding: 2px 5px;
    font-size: 12px;
    border: 1px solid #0B7E9D;
    border-radius: 10px;
    background-color: transparent;
    color: #0B7E9D;
    min-width: 120px;
    margin-top: 0;
    margin-bottom: 0;
    margin-left: 0;
    margin-right: 5px;
}

#chat-knowledge-base {
    display: none;
}

#chat-knowledge-base:disabled, #chat-summary-button:disabled {
    color: #999;
    border-color: #ccc;
    background-color: #f0f0f0;
}

#chat-send-button {
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    background-color: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-2px);
    margin-left: auto;
}

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

#chat-send-button svg {
    width: 20px;
    height: 20px;
    fill: #0B7E9D;
}

#chat-send-button:disabled svg {
    fill: #999;
}

/* 默认状态：显示发送图标，隐藏停止图标 */
.chat-icon-send {
    display: block; /* 或者 inline-block，取决于原有布局 */
    transition: opacity 0.2s;
}

.chat-icon-stop {
    display: none;
    font-size: 18px;
    color: #d32f2f; /* 红色停止图标 */
}

/* 生成中状态 (Added via JS)：隐藏发送图标，显示停止图标 */
#chat-send-button.generating .chat-icon-send {
    display: none;
}

#chat-send-button.generating .chat-icon-stop {
    display: inline-block;
    animation: pulse-red 2s infinite; /* 可选：加个呼吸效果提示正在运行 */
}

/* 可选：给停止按钮加个简单的呼吸动画 */
@keyframes pulse-red {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.9); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

#chat-knowledge-base, #chat-summary-button, #chat-send-button, #chat-user-input {
    transition: all 0.3s ease;
}

.chat-message {
    max-width: 80%;
    margin-bottom: 15px;
    padding: 10px 14px;
    font-size: 14px !important;
    border-radius: 12px;
    word-wrap: break-word;
    position: relative;
    line-height: 1.5;
    float: none; 
    clear: both;
}

.chat-user-message {
    background-color: rgba(11, 126, 157, 0.1) !important;
    color: #333;
    margin-left: auto; 
    margin-right: 0;
    border-bottom-right-radius: 2px;
    text-align: left;
}

.chat-assistant-message {
    background-color: #f5f7f8 !important;
    color: #333;
    margin-right: auto; 
    margin-left: 0;
    border-bottom-left-radius: 2px;
    text-align: left;
}

.chat-message p {
    margin: 0;
    font-size: 14px;
    color: #0c0c0c !important;
}

.chat-message ul,
.chat-message ol {
    margin: 5px 0;
    padding-left: 2em !important;
}

.chat-message ul li {
    list-style-type: disc; /* 使用实心圆点 */
    list-style-position: outside; /* 确保符号在文字区块以外 */
    margin-bottom: 5px;
}

.chat-message ol li {
    list-style-type: decimal; /* 使用数字 */
    list-style-position: outside;
    margin-bottom: 5px;
}

.chat-message pre {
    background-color: rgba(249, 246, 229, 0.8);
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-message code {
    background-color: rgba(215, 185, 161, 0.3);
    padding: 2px 4px;
    border-radius: 3px;
    word-break: break-all; /* 强制长单词或 URL 在任意位置换行，以防止溢出容器 */
    overflow-wrap: break-word; /* 允许在单词之间换行，如果单词本身过长，则会强制打断。与 `word-break: break-all` 结合使用，可以更好地处理各种情况。*/
}

.chat-message pre code {
    padding: 0;
    background-color: transparent;
    border-radius: 0;
    white-space: pre-wrap !important;
    word-wrap: break-word;
    white-space: inherit;
}

.chat-assistant-message code {
    background-color: rgba(215, 185, 161, 0.3);
    padding: 2px 4px;
    border-radius: 3px;
    word-break: break-all; /* 强制长单词或 URL 在任意位置换行，以防止溢出容器 */
    overflow-wrap: break-word; /* 允许在单词之间换行，如果单词本身过长，则会强制打断。与 `word-break: break-all` 结合使用，可以更好地处理各种情况。*/
    white-space: pre-wrap; /* 确保 <pre> 标签内的 <code> 也能正确处理空白并换行。虽然父级 pre 已经有此设置，但再次声明可确保其优先级。*/
}

.chat-widget-hidden {
    display: none;
}

.chat-area {
    display: flex;
    flex-direction: column;
    padding: 15px;
    overflow-y: auto;
}

.resize-modal {
    position: absolute;
    bottom: 2px;
    right: 2px;
    cursor: se-resize;
    z-index: 10002; /* 确保在最上层，方便点击 */
    width: 18px;
    height: 18px;
    line-height: 1; /* 防止 SVG 被撑开 */
}

.chat-note {
    width: 100%;
    margin: 8px auto 0;
    font-size: 12px;
    color: #999;
    line-height: 1.4;
    text-align: left;
    padding: 0 5px;     /* 防止文字贴边 */
    box-sizing: border-box;
}

.chat-loading-box {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 150px; /* 保证有足够宽度显示动画 */
    row-gap: 8px;
    color: #999;
    padding: 5px 0;
}

.chat-loading-outer {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 6px; /* 稍微调细一点更精致 */
    background-color: #e2e8f0;
    border-radius: 4px;
    z-index: 1;
}

.chat-loading-inner {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    /* 调整颜色透明度，确保在灰色背景上可见 */
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(11, 126, 157, 0.2) 15%,
        rgba(11, 126, 157, 1) 50%, 
        rgba(11, 126, 157, 0.2) 85%,
        transparent 100%
    );
    transform: translateX(-100%);
    animation: chatLoding 1.2s linear infinite;
}

@keyframes chatLoding {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.chat-feedback-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    column-gap: 10px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.05);
    width: 100%;
}

.chat-feedback-item {
    display: flex;
    column-gap: 8px;
}

.chat-feedback-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    column-gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    border: none;
    transition: all 0.2s;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    background-color: transparent;
}

.chat-feedback-btn.chat-copy-btn {
    color: rgba(237, 77, 76, 1);
    background-color: rgba(237, 77, 76, 0.09);
}
.chat-feedback-btn.chat-copy-btn:hover {
    color: #FFF;
    background-color: rgba(237, 77, 76, 1);
}

.chat-feedback-btn.chat-clear-btn {
    color: rgba(86, 186, 51, 1);
    background-color: rgba(86, 186, 51, 0.09);
}
.chat-feedback-btn.chat-clear-btn:hover {
    color: #FFF;
    background-color: rgba(86, 186, 51, 1);
}

.chat-feedback-btn.chat-clear-btn svg path {
    fill: rgba(86, 186, 51, 1);
    transition: fill 0.2s;
}
.chat-feedback-btn.chat-clear-btn:hover svg path {
    fill: #FFF;
}

.chat-feedback-btn.chat-like-btn {
    color: rgba(255, 130, 20, 1);
    background-color: rgba(255, 130, 20, 0.09);
}
.chat-feedback-btn.chat-like-btn:hover,
.chat-feedback-btn.chat-like-btn.active {
    color: #FFF;
    background-color: rgba(255, 130, 20, 1);
}

.chat-feedback-btn.chat-dislike-btn {
    color: rgba(20, 101, 255, 1);
    background-color: rgba(20, 101, 255, 0.09);
}
.chat-feedback-btn.chat-dislike-btn:hover,
.chat-feedback-btn.chat-dislike-btn.active {
    color: #FFF;
    background-color: rgba(20, 101, 255, 1);
}

.chat-feedback-text {
    font-size: 14px;
    font-weight: 500;
}

@media (max-width: 1200px) {
    #chat-user-input {
        height: 40px; /* 2 line */
    }

    #chat-widget-wrapper {
        width: 90vw;
    }
}