#ai-assistant-ball {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #007AFF;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 2147483646;
    font-size: 24px;
    color: white;
    transition: transform 0.3s ease, background-color 0.3s ease;
    user-select: none;
    pointer-events: auto;
}

#ai-assistant-ball:hover {
    transform: scale(1.1);
    background-color: #0056b3;
}

#ai-assistant-dialog {
    position: fixed;
    right: 20px;
    bottom: 80px;
    width: min(400px, 90vw);
    height: min(500px, 80vh);
    min-width: 280px;
    min-height: 300px;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 2147483645;
    overflow: hidden;
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: scale(0.3);
    pointer-events: none;
    visibility: hidden;
}

#ai-assistant-dialog.show {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
    visibility: visible;
}

/* 复制原有的popup.css中的样式，但修改选择器 */
#ai-assistant-dialog .container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background-color: #f5f5f5;
    position: relative;
    z-index: 1;
}

#ai-assistant-dialog .header {
    padding: 8px 16px;
    border-bottom: 1px solid #eee;
    background-color: #fff;
    min-height: 0px;
    display: flex;
    align-items: center;
}

#ai-assistant-dialog .chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: #fff;
    min-height: 0;
    position: relative;
    z-index: 1;
}

/* 添加所有popup.css中的样式，加上#ai-assistant-dialog前缀 */
#ai-assistant-dialog .welcome-message {
    text-align: center;
    color: #666;
    padding: 10px;
    margin-bottom: 10px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

#ai-assistant-dialog .messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    position: relative;
    z-index: 1;
}

#ai-assistant-dialog .message {
    max-width: min(85%, calc(100% - 40px));
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    position: relative;
}

#ai-assistant-dialog .user-message {
    align-self: flex-end !important;
    background-color: #007AFF !important;
    color: white !important;
    border-radius: 12px 12px 2px 12px !important;
    max-width: 85% !important;
}

#ai-assistant-dialog .assistant-message {
    align-self: flex-start;
    background-color: #f0f0f0;
    color: #000;
    border-radius: 12px 12px 12px 2px;
    font-size: 14px;
    line-height: 1.5;
}

/* Markdown 样式 */
#ai-assistant-dialog .assistant-message p {
    margin: 0.5em 0;
}

#ai-assistant-dialog .assistant-message code {
    background-color: #f3f3f3;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}

#ai-assistant-dialog .assistant-message pre {
    background-color: #f6f8fa;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
}

#ai-assistant-dialog .assistant-message pre code {
    background-color: transparent;
    padding: 0;
}

#ai-assistant-dialog .assistant-message ul,
#ai-assistant-dialog .assistant-message ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

#ai-assistant-dialog .assistant-message blockquote {
    border-left: 4px solid #ddd;
    margin: 0.5em 0;
    padding-left: 1em;
    color: #666;
}

#ai-assistant-dialog .assistant-message a {
    color: #0366d6;
    text-decoration: none;
}

#ai-assistant-dialog .assistant-message a:hover {
    text-decoration: underline;
}

#ai-assistant-dialog .assistant-message table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
}

#ai-assistant-dialog .assistant-message th,
#ai-assistant-dialog .assistant-message td {
    border: 1px solid #ddd;
    padding: 6px 8px;
}

#ai-assistant-dialog .assistant-message th {
    background-color: #f6f8fa;
}

#ai-assistant-dialog .typing-indicator {
    display: inline-block;
    padding: 4px 8px;
}

#ai-assistant-dialog .typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #90909090;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1s infinite ease-in-out;
}

#ai-assistant-dialog .typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

#ai-assistant-dialog .typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

#ai-assistant-dialog .input-container {
    position: relative !important;
    display: flex !important;
    gap: 8px !important;
    padding: 12px !important;
    background-color: white !important;
    border-top: 1px solid #F3F4F6 !important;
    z-index: 2;
}

#ai-assistant-dialog textarea {
    display: block !important;
    width: 100% !important;
    padding: 8px 12px !important;
    padding-right: 44px !important;
    /* 为发送按钮留出空间 */
    border: 1px solid #E5E7EB !important;
    border-radius: 18px !important;
    resize: none !important;
    font-family: inherit !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    background: #F9FAFB !important;
    color: #333 !important;
    transition: all 0.2s ease !important;
    min-height: 36px !important;
    max-height: 120px !important;
}

#ai-assistant-dialog #askButton {
    position: absolute !important;
    right: 24px !important;
    /* 考虑输入容器的内边距 */
    bottom: 50% !important;
    transform: translateY(50%) !important;
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #007AFF !important;
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 2px 6px rgba(0, 122, 255, 0.2) !important;
    z-index: 1 !important;
}

#ai-assistant-dialog #askButton::before {
    content: "" !important;
    display: block !important;
    width: 0 !important;
    height: 0 !important;
    border-style: solid !important;
    border-width: 6px 0 6px 10px !important;
    border-color: transparent transparent transparent white !important;
    margin-left: 3px !important;
    transition: all 0.2s ease !important;
}

#ai-assistant-dialog #askButton.generating::before {
    content: "" !important;
    width: 10px !important;
    height: 10px !important;
    border: none !important;
    background-color: white !important;
    margin-left: 0 !important;
}

#ai-assistant-dialog #askButton:hover {
    background: #0056b3 !important;
    transform: translateY(50%) scale(1.05) !important;
    box-shadow: 0 4px 8px rgba(0, 122, 255, 0.3) !important;
}

#ai-assistant-dialog #askButton:active {
    transform: translateY(50%) scale(0.95) !important;
    box-shadow: 0 2px 4px rgba(0, 122, 255, 0.2) !important;
}

#ai-assistant-dialog #askButton:disabled {
    background: #E0E0E0 !important;
    cursor: not-allowed !important;
    transform: translateY(50%) !important;
    box-shadow: none !important;
}

#ai-assistant-dialog #askButton:disabled::before {
    border-color: transparent transparent transparent rgba(255, 255, 255, 0.6) !important;
}

#ai-assistant-dialog textarea:focus {
    border-color: #007AFF !important;
    outline: none !important;
    background: white !important;
}

/* 开关样 */
#ai-assistant-dialog .header {
    padding: 8px 16px;
    border-bottom: 1px solid #eee;
    background-color: #fff;
}

#ai-assistant-dialog .toggle-ball {
    display: flex;
    align-items: center;
    gap: 8px;
}

#ai-assistant-dialog .toggle-label {
    font-size: 14px;
    color: #666;
}

#ai-assistant-dialog .switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

#ai-assistant-dialog .switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

#ai-assistant-dialog .switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

#ai-assistant-dialog .switch .slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

#ai-assistant-dialog .switch input:checked+.slider {
    background-color: #007AFF;
}

#ai-assistant-dialog .switch input:checked+.slider:before {
    transform: translateX(20px);
}

/* 自定义滚动条样式 */
#ai-assistant-dialog ::-webkit-scrollbar {
    width: 8px;
}

#ai-assistant-dialog ::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#ai-assistant-dialog ::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#ai-assistant-dialog ::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 添加动画关键帧 */
@keyframes slideIn {
    from {
        transform: scale(0.3);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: scale(1);
        opacity: 1;
    }

    to {
        transform: scale(0.3);
        opacity: 0;
    }
}

/* 应用动画 */
#ai-assistant-dialog.show {
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#ai-assistant-dialog.hide {
    animation: slideOut 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 消息容器的相对定位，用于放置复制按钮 */
#ai-assistant-dialog .message {
    position: relative;
}

/* 右键菜单样式 */
.context-menu {
    position: fixed !important;
    background: white !important;
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    padding: 4px 0 !important;
    z-index: 2147483647;
    min-width: 150px !important;
}

.context-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-item:hover {
    background-color: #f5f5f5;
}

/* 复制成功提示样式 */
.copy-toast {
    position: fixed !important;
    background-color: rgba(0, 0, 0, 0.8) !important;
    color: white !important;
    padding: 8px 16px !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    z-index: 2147483647;
    pointer-events: none !important;
    animation: fadeInOut 2s ease !important;
    white-space: nowrap !important;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) translateY(10px);
    }

    20% {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(0);
    }

    80% {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(0);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) translateY(-10px);
    }
}

/* 悬浮球边缘状态样式 */
#ai-assistant-ball.edge-left {
    transform: translateX(-50%) !important;
    left: 0 !important;
    transition: all 0.3s ease;
}

#ai-assistant-ball.edge-right {
    transform: translateX(50%) !important;
    right: 0 !important;
    left: auto !important;
    transition: all 0.3s ease;
}

#ai-assistant-ball.edge-top {
    transform: translateY(-50%) !important;
    top: 0 !important;
    transition: all 0.3s ease;
}

#ai-assistant-ball.edge-bottom {
    transform: translateY(50%) !important;
    bottom: 0 !important;
    top: auto !important;
    transition: all 0.3s ease;
}

/* 悬浮时恢复完整大小 */
#ai-assistant-ball.edge-left:hover {
    transform: translateX(0) !important;
}

#ai-assistant-ball.edge-right:hover {
    transform: translateX(0) !important;
}

#ai-assistant-ball.edge-top:hover {
    transform: translateY(0) !important;
}

#ai-assistant-ball.edge-bottom:hover {
    transform: translateY(0) !important;
}

/* 右键菜单样式 */
.ball-context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 4px 0;
    z-index: 10000;
    min-width: 100px;
}

.ball-context-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ball-context-menu-item:hover {
    background-color: #f5f5f5;
}

/* 修改悬浮球和设置按钮的容器样式 */
.ball-container {
    position: fixed;
    z-index: 9999;
    width: 50px;
    height: 50px;
}

/* 创建一个hover区域，包含悬浮球和设置按钮 */
.ball-hover-area {
    position: absolute;
    width: 100px;
    height: 100px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* 设置按钮基础样式 */
.settings-button {
    width: 32px;
    height: 32px;
    background-color: #007AFF;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    color: white;
    font-size: 16px;
    position: absolute;
    left: 50%;
    top: 100%;
    margin-top: 8px;
    transform: translateX(-50%) scale(0.8);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 当容器被hover时显示设置按钮 */
.ball-container:hover .settings-button {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) scale(1);
}

/* 设置按钮hover效果 */
.settings-button:hover {
    background-color: #0056b3;
}

/* 当悬浮球在底部边缘时，设置按钮显示在上方 */
.ball-container:has(#ai-assistant-ball.edge-bottom) .settings-button {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 8px;
}

/* 当悬浮球在顶部边缘时，设置按钮显示在下方 */
.ball-container:has(#ai-assistant-ball.edge-top) .settings-button {
    top: 100%;
    bottom: auto;
    margin-bottom: 0;
    margin-top: 8px;
}

/* 当悬浮球在左边缘时，设置按钮显示在下方 */
.ball-container:has(#ai-assistant-ball.edge-left) .settings-button {
    top: 100%;
    bottom: auto;
    margin-bottom: 0;
    margin-top: 8px;
}

/* 当悬浮球在右边缘时，设置按钮显示在下方 */
.ball-container:has(#ai-assistant-ball.edge-right) .settings-button {
    top: 100%;
    bottom: auto;
    margin-bottom: 0;
    margin-top: 8px;
}

/* 确保置按钮可以接收点击事件 */
.settings-button {
    pointer-events: auto;
}

/* 中断消息样式 */
#ai-assistant-dialog .message.assistant-message[style*="text-align: center"] {
    max-width: none !important;
    margin: 4px 0 !important;
    opacity: 0.7 !important;
}

/* 调整大小的手柄样式 */
#ai-assistant-dialog .resize-handle {
    position: absolute !important;
    width: 20px !important;
    height: 20px !important;
    right: 0 !important;
    bottom: 0 !important;
    cursor: se-resize !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 2147483645 !important;
}

/* 调整手柄的图标 */
#ai-assistant-dialog .resize-handle::before {
    content: "" !important;
    width: 8px !important;
    height: 8px !important;
    border-right: 2px solid #999 !important;
    border-bottom: 2px solid #999 !important;
    position: absolute !important;
    right: 4px !important;
    bottom: 4px !important;
}

/* 确保对话框可以调整大小 */
#ai-assistant-dialog {
    resize: none !important;
    min-width: 300px !important;
    min-height: 400px !important;
}

/* 用户消息中的Markdown样式 */
#ai-assistant-dialog .user-message code {
    background-color: rgba(255, 255, 255, 0.1) !important;
    padding: 2px 4px !important;
    border-radius: 4px !important;
    font-family: monospace !important;
}

#ai-assistant-dialog .user-message pre {
    background-color: rgba(255, 255, 255, 0.1) !important;
    padding: 8px !important;
    border-radius: 4px !important;
    overflow-x: auto !important;
    margin: 8px 0 !important;
}

#ai-assistant-dialog .user-message a {
    color: white !important;
    text-decoration: underline !important;
}

#ai-assistant-dialog .user-message p {
    margin: 0 !important;
}

#ai-assistant-dialog .user-message ul,
#ai-assistant-dialog .user-message ol {
    margin: 4px 0 !important;
    padding-left: 20px !important;
}

#ai-assistant-dialog .user-message blockquote {
    border-left: 3px solid rgba(255, 255, 255, 0.3) !important;
    margin: 4px 0 !important;
    padding-left: 8px !important;
}

/* 确保对话框内容不会被遮挡 */
#ai-assistant-dialog::before {
    content: '' !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: -1 !important;
    pointer-events: none !important;
}

/* 添加遮罩层样式 */
.dialog-overlay {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background-color: transparent !important;
    z-index: 2147483644 !important;
    /* 比对话框低一级 */
    pointer-events: none !important;
}

/* 拖动时显示遮罩层 */
.dialog-overlay.dragging {
    display: block !important;
    pointer-events: auto !important;
}

/* 确保对话框在遮罩层之上 */
#ai-assistant-dialog {
    /* ... 其他样式保持不变 ... */
    z-index: 2147483645 !important;
}

/* 修改Tokens统计样式，隐藏显示 */
#ai-assistant-dialog .tokens-counter {
    position: absolute !important;
    top: 0 !important;
    right: 8px !important;
    font-size: 12px !important;
    color: #666 !important;
    padding: 4px 8px !important;
    background: transparent !important;
    z-index: 1 !important;
    user-select: none !important;
    display: none !important;
}