/* ============================================================
 * Registerpilot AI 问答助手 - 聊天组件样式
 * 用法：在 HTML 中引入本文件，然后调用 RegisterPilotChat.init()
 * ============================================================ */

.rp-chat-root {
    --rp-primary: #185FA5;
    --rp-primary-hover: #144d85;
    --rp-bg: #ffffff;
    --rp-bg-soft: #f9f9f9;
    --rp-border: #e0e0e0;
    --rp-text: #2c3e50;
    --rp-text-soft: #7f8c8d;
    --rp-user-bubble: #007bff;
    --rp-user-text: #ffffff;
    --rp-bot-bubble: #e9ecef;
    --rp-bot-text: #2c3e50;
    --rp-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --rp-radius: 12px;
    --rp-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.rp-chat-root * {
    box-sizing: border-box;
    font-family: var(--rp-font);
}

/* 浮动触发按钮 */
.rp-chat-trigger {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #fff;
    color: var(--rp-primary);
    border: 2px solid var(--rp-primary);
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    transition: transform 0.2s, background 0.2s, color 0.2s;
}

.rp-chat-trigger:hover {
    background: var(--rp-primary);
    color: #fff;
    transform: scale(1.06);
}

.rp-chat-trigger svg {
    width: 24px;
    height: 24px;
    display: block;
}

.rp-chat-trigger.rp-hidden {
    display: none;
}

/* 聊天主窗口 */
.rp-chat-window {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 380px;
    height: 540px;
    background: var(--rp-bg);
    border-radius: var(--rp-radius);
    box-shadow: var(--rp-shadow);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    border: 1px solid var(--rp-border);
}

.rp-chat-window.rp-hidden {
    display: none;
}

/* 顶部标题栏 */
.rp-chat-header {
    background: var(--rp-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.rp-chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
}

.rp-chat-header-title .rp-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;
}

.rp-chat-header-actions {
    display: flex;
    gap: 4px;
}

.rp-chat-header-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.2s;
}

.rp-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* 消息列表区 */
.rp-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--rp-bg-soft);
    scroll-behavior: smooth;
}

.rp-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.rp-chat-messages::-webkit-scrollbar-thumb {
    background: var(--rp-border);
    border-radius: 3px;
}

/* 欢迎卡片 */
.rp-welcome {
    text-align: center;
    padding: 12px 10px;
    color: var(--rp-text-soft);
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 12px;
}

.rp-welcome-title {
    font-size: 18px;
    color: var(--rp-text);
    font-weight: 600;
    margin-bottom: 6px;
}

.rp-welcome strong {
    color: var(--rp-text);
    font-weight: 600;
}

/* 推荐问题列表 */
.rp-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.rp-suggestion-chip {
    background: #fff;
    border: 1px solid var(--rp-border);
    border-radius: 18px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--rp-text);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}

.rp-suggestion-chip:hover {
    background: var(--rp-primary);
    color: #fff;
    border-color: var(--rp-primary);
}

.rp-suggestion-chip .rp-suggestion-cat {
    background: #ecf0f1;
    color: var(--rp-text-soft);
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

.rp-suggestion-chip:hover .rp-suggestion-cat {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* 消息气泡 */
.rp-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: rp-fade-in 0.3s ease;
}

@keyframes rp-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.rp-message.rp-user {
    align-self: flex-end;
    align-items: flex-end;
}

.rp-message.rp-bot {
    align-self: flex-start;
    align-items: flex-start;
}

.rp-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.rp-message.rp-user .rp-bubble {
    background: var(--rp-user-bubble);
    color: var(--rp-user-text);
    border-bottom-right-radius: 4px;
}

.rp-message.rp-bot .rp-bubble {
    background: var(--rp-bot-bubble);
    color: var(--rp-bot-text);
    border-bottom-left-radius: 4px;
}

/* Bot 消息支持 Markdown */
.rp-message.rp-bot .rp-bubble h1,
.rp-message.rp-bot .rp-bubble h2,
.rp-message.rp-bot .rp-bubble h3,
.rp-message.rp-bot .rp-bubble h4 {
    margin: 6px 0 4px;
    line-height: 1.3;
}

.rp-message.rp-bot .rp-bubble h1 { font-size: 15px; }
.rp-message.rp-bot .rp-bubble h2 { font-size: 14px; }
.rp-message.rp-bot .rp-bubble h3 { font-size: 14px; font-weight: 600; }
.rp-message.rp-bot .rp-bubble h4 { font-size: 13px; font-weight: 600; }

.rp-message.rp-bot .rp-bubble p {
    margin: 4px 0;
}

.rp-message.rp-bot .rp-bubble ul,
.rp-message.rp-bot .rp-bubble ol {
    margin: 4px 0;
    padding-left: 18px;
}

.rp-message.rp-bot .rp-bubble li {
    margin: 2px 0;
}

.rp-message.rp-bot .rp-bubble code {
    background: rgba(0, 0, 0, 0.08);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 13px;
}

.rp-message.rp-bot .rp-bubble pre {
    background: rgba(0, 0, 0, 0.08);
    padding: 8px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
}

.rp-message.rp-bot .rp-bubble table {
    border-collapse: collapse;
    margin: 6px 0;
    font-size: 12px;
    width: 100%;
}

.rp-message.rp-bot .rp-bubble th,
.rp-message.rp-bot .rp-bubble td {
    border: 1px solid var(--rp-border);
    padding: 4px 6px;
    text-align: left;
}

.rp-message.rp-bot .rp-bubble th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.rp-message.rp-bot .rp-bubble strong {
    font-weight: 600;
}

.rp-message.rp-bot .rp-bubble blockquote {
    border-left: 3px solid var(--rp-primary);
    padding-left: 10px;
    margin: 6px 0;
    color: var(--rp-text-soft);
    font-size: 13px;
}

.rp-message-time {
    font-size: 11px;
    color: var(--rp-text-soft);
    margin-top: 4px;
    padding: 0 4px;
}

/* 正在输入指示器 */
.rp-typing {
    align-self: flex-start;
    background: var(--rp-bot-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    margin-bottom: 12px;
    display: flex;
    gap: 4px;
}

.rp-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--rp-text-soft);
    animation: rp-typing-bounce 1.4s infinite ease-in-out;
}

.rp-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.rp-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes rp-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* 错误消息 */
.rp-message.rp-error .rp-bubble {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}

/* 输入区 */
.rp-chat-input-area {
    padding: 10px 12px 8px;
    border-top: 1px solid var(--rp-border);
    background: var(--rp-bg);
    flex-shrink: 0;
}

.rp-chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.rp-chat-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--rp-border);
    border-radius: 20px;
    font-size: 14px;
    font-family: var(--rp-font);
    resize: none;
    min-height: 38px;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.4;
}

.rp-chat-input:focus {
    border-color: var(--rp-primary);
    box-shadow: 0 0 0 2px rgba(24, 95, 165, 0.08);
}

.rp-chat-input:disabled {
    background: var(--rp-bg-soft);
    cursor: not-allowed;
}

.rp-chat-send-btn {
    background: var(--rp-primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    min-width: 60px;
    height: 38px;
}

.rp-chat-send-btn:hover:not(:disabled) {
    background: var(--rp-primary-hover);
}

.rp-chat-send-btn:disabled {
    background: var(--rp-text-soft);
    cursor: not-allowed;
}

.rp-chat-disclaimer {
    font-size: 11px;
    color: var(--rp-text-soft);
    margin-top: 6px;
    text-align: center;
    line-height: 1.3;
}

/* 移动端响应式 */
@media (max-width: 480px) {
    .rp-chat-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    
    .rp-chat-trigger {
        bottom: 24px;
        right: 24px;
        width: 48px;
        height: 48px;
        font-size: 22px;
    }
}
