/* ================================================================
 * DS IM v5.5.0 — 站内私信
 * ================================================================ */

:root {
    --ds-im-primary: #6366f1;
    --ds-im-bg: #f8fafc;
    --ds-im-card: #ffffff;
    --ds-im-text: #0f172a;
    --ds-im-text-2: #64748b;
    --ds-im-border: #e2e8f0;
    --ds-im-bubble-mine: linear-gradient(135deg, #6366f1, #8b5cf6);
    --ds-im-bubble-peer: #f1f5f9;
}

/* ---- 通用 ---- */
.ds-im-wrap {
    display: flex;
    max-width: 1000px;
    height: 70vh;
    min-height: 500px;
    margin: 0 auto;
    background: var(--ds-im-card);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--ds-im-text);
}
.ds-im-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--ds-im-text-2);
    padding: 40px;
    text-align: center;
    background: var(--ds-im-bg);
}
.ds-im-empty a { color: var(--ds-im-primary); text-decoration: none; font-weight: 600; }

/* ---- 对话列表 ---- */
.ds-im-list {
    width: 320px;
    border-right: 1px solid var(--ds-im-border);
    display: flex;
    flex-direction: column;
}
.ds-im-list-head {
    padding: 16px;
    border-bottom: 1px solid var(--ds-im-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--ds-im-bg);
}
.ds-im-list-head h3 {
    margin: 0;
    font-size: 16px;
}
.ds-im-btn-new {
    padding: 4px 12px;
    background: var(--ds-im-primary);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
}
.ds-im-conv-ul {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
    overflow-y: auto;
}
.ds-im-conv-li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ds-im-border);
    cursor: pointer;
    transition: background 0.15s;
}
.ds-im-conv-li:hover {
    background: var(--ds-im-bg);
}
.ds-im-conv-li.is-unread {
    background: linear-gradient(90deg, #eef2ff, transparent);
}
.ds-im-conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.ds-im-conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ds-im-conv-meta {
    flex: 1;
    min-width: 0;
}
.ds-im-conv-name {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ds-im-badge {
    background: var(--ds-im-error, #ef4444);
    color: #fff;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 600;
    margin-left: auto;
}
.ds-im-conv-time {
    font-size: 12px;
    color: var(--ds-im-text-2);
    margin-top: 4px;
}

/* ---- 聊天面板 ---- */
.ds-im-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.ds-im-chat-head {
    padding: 12px 16px;
    border-bottom: 1px solid var(--ds-im-border);
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ds-im-bg);
}
.ds-im-back {
    color: var(--ds-im-text-2);
    text-decoration: none;
    font-size: 18px;
    padding: 0 8px;
}
.ds-im-chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.ds-im-chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ds-im-chat-name {
    font-size: 14px;
    font-weight: 600;
    flex: 1;
}
.ds-im-chat-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}
.ds-im-chat-actions button:hover { background: var(--ds-im-border); }

.ds-im-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--ds-im-bg);
}
.ds-im-chat-empty {
    text-align: center;
    color: var(--ds-im-text-2);
    padding: 60px 20px;
    font-size: 14px;
}

/* ---- 消息气泡 ---- */
.ds-im-msg {
    display: flex;
    margin-bottom: 16px;
    align-items: flex-start;
    gap: 8px;
}
.ds-im-msg.is-mine {
    flex-direction: row-reverse;
}
.ds-im-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.ds-im-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ds-im-msg-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--ds-im-bubble-peer);
    color: var(--ds-im-text);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
}
.ds-im-msg.is-mine .ds-im-msg-bubble {
    background: var(--ds-im-bubble-mine);
    color: #fff;
}
.ds-im-msg-content {
    white-space: pre-wrap;
}
.ds-im-msg-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}

/* ---- 输入框 ---- */
.ds-im-chat-form {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--ds-im-border);
    background: var(--ds-im-card);
}
.ds-im-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--ds-im-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    box-sizing: border-box;
    min-height: 40px;
    max-height: 120px;
}
.ds-im-input:focus { border-color: var(--ds-im-primary); }
.ds-im-send-btn {
    padding: 0 20px;
    background: var(--ds-im-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.ds-im-send-btn:hover { background: #4f46e5; }
.ds-im-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- 响应式 ---- */
@media (max-width: 768px) {
    .ds-im-wrap { height: 80vh; }
    .ds-im-list { width: 100%; }
    .ds-im-wrap:has(.ds-im-chat) .ds-im-list { display: none; }
}

/* ---- 嵌入模式 ---- */
.ds-im-embed {
    height: 500px;
    max-width: 800px;
    margin: 0 auto;
    border: 1px solid var(--ds-im-border);
}

/* ---- 用户主页发私信按钮 ---- */
.ds-btn-send-im {
    display: inline-block;
    padding: 8px 18px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    text-decoration: none;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}
.ds-btn-send-im:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* ---- 暗黑模式 ---- */
@media (prefers-color-scheme: dark) {
    :root {
        --ds-im-bg: #0f172a;
        --ds-im-card: #1e293b;
        --ds-im-text: #f1f5f9;
        --ds-im-text-2: #94a3b8;
        --ds-im-border: #334155;
        --ds-im-bubble-peer: #334155;
    }
    .ds-im-conv-li.is-unread { background: linear-gradient(90deg, #312e81, transparent); }
    .ds-im-input { background: #0f172a; color: var(--ds-im-text); }
}
