/* IM 小部件容器 */
.im-widget {
    position: fixed;
    bottom: 50px;
    right: 20px;
    z-index: 20;
    font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

/* IM 聊天窗口 */
.im-chat-window {
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
    transform-origin: bottom right;
}

/* IM 聊天窗口隐藏 */
.im-chat-window.hidden {
    display: none;
}

/* IM 头部 */
.im-header {
    background: linear-gradient(135deg, #0078d7 0%, #005fb3 100%);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.im-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    border: 2px solid white;
}

.im-header-info {
    flex: 1;
}

.im-header-name {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.im-header-status {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
    margin-top: 2px;
}

.im-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.im-close-btn:hover {
    transform: scale(1.2);
}

/* IM 消息容器 */
.im-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f9f9f9;
}

.im-messages::-webkit-scrollbar {
    width: 6px;
}

.im-messages::-webkit-scrollbar-track {
    background: transparent;
}

.im-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.im-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* IM 消息气泡 */
.im-message {
    display: flex;
    gap: 8px;
    animation: fadeIn 0.3s ease-out;
}

.im-message.user {
    justify-content: flex-end;
}

.im-message.bot {
    justify-content: flex-start;
}

.im-message-content {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
}

.im-message.bot .im-message-content {
    background: #e8e8e8;
    color: #333;
    border-bottom-left-radius: 4px;
}

.im-message.user .im-message-content {
    background: linear-gradient(135deg, #0078d7 0%, #005fb3 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.im-message-time {
    font-size: 11px;
    color: #999;
    opacity: 0;
    transition: opacity 0.2s;
}

.im-message:hover .im-message-time {
    opacity: 1;
}

/* IM 输入框容器 */
.im-input-container {
    padding: 12px;
    border-top: 1px solid #e0e0e0;
    background: white;
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.im-input-field {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    transition: border-color 0.2s;
}

.im-input-field:focus {
    outline: none;
    border-color: #0078d7;
    box-shadow: 0 0 0 2px rgba(0, 120, 215, 0.1);
}

.im-send-btn {
    background: linear-gradient(135deg, #0078d7 0%, #005fb3 100%);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    min-width: 50px;
}

.im-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 120, 215, 0.3);
}

.im-send-btn:active {
    transform: translateY(0);
}

.im-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* IM 开启按钮 */
.im-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0078d7 0%, #005fb3 100%);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 120, 215, 0.4);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

.im-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 120, 215, 0.5);
}

.im-button:active {
    transform: scale(0.95);
}

.im-button.hidden {
    display: none;
}

/* IM 未读消息徽章 */
.im-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    border: 2px solid white;
    min-width: 24px;
}

.im-button {
    position: relative;
}

/* 动画 */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(0, 120, 215, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(0, 120, 215, 0.6);
    }
}

/* 响应式设计 */
@media (max-width: 480px) {
    .im-chat-window {
        width: calc(100vw - 20px);
        height: 70vh;
        max-height: 500px;
        bottom: 70px;
        right: 10px;
        left: 10px;
    }

    .im-button {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    .im-message-content {
        max-width: 85%;
    }
}

/* 深色主题支持 */
body[data-theme="dark"] .im-chat-window {
    background: #1f1f1f;
    color: #e6e6e6;
}

body[data-theme="dark"] .im-header {
    background: linear-gradient(135deg, #1f1f1f 0%, #2b2b2b 100%);
}

body[data-theme="dark"] .im-messages {
    background: #161616;
}

body[data-theme="dark"] .im-message.bot .im-message-content {
    background: #2b2b2b;
    color: #e6e6e6;
}

body[data-theme="dark"] .im-input-container {
    background: #1f1f1f;
    border-top-color: #333;
}

body[data-theme="dark"] .im-input-field {
    background: #2b2b2b;
    color: #e6e6e6;
    border-color: #333;
}

body[data-theme="dark"] .im-input-field:focus {
    border-color: #0078d7;
}
