/* ==========================================================================
   KKAI Widget — 在线客服 / AI 即时沟通
   主题：深色玻璃，与 dashboard/index.html 保持一致
   ========================================================================== */

/* 悬浮按钮 */
.kkai-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.45),
                0 0 0 1px rgba(255,255,255,0.12) inset;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    animation: kkai-pulse 2.5s infinite;
}

.kkai-fab:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 40px rgba(59, 130, 246, 0.6),
                0 0 0 1px rgba(255,255,255,0.2) inset;
}

.kkai-fab:active { transform: scale(0.96); }

@keyframes kkai-pulse {
    0% { box-shadow: 0 8px 32px rgba(59, 130, 246, 0.45), 0 0 0 0 rgba(59, 130, 246, 0.55); }
    70% { box-shadow: 0 8px 32px rgba(59, 130, 246, 0.45), 0 0 0 18px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 8px 32px rgba(59, 130, 246, 0.45), 0 0 0 0 rgba(59, 130, 246, 0); }
}

.kkai-fab svg {
    width: 32px;
    height: 32px;
    fill: currentColor;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.kkai-fab .kkai-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #0f172a;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s, transform 0.2s;
}
.kkai-fab .kkai-badge.show { opacity: 1; transform: scale(1); }

/* 聊天面板 */
.kkai-panel {
    position: fixed;
    right: 24px;
    bottom: 100px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 640px;
    max-height: calc(100vh - 140px);
    border-radius: 24px;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(28px) saturate(160%);
    -webkit-backdrop-filter: blur(28px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(255,255,255,0.05) inset;
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(30px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.kkai-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

@media (max-width: 480px) {
    .kkai-panel {
        right: 12px;
        bottom: 90px;
        left: 12px;
        width: auto;
        max-width: none;
        height: calc(100vh - 110px);
        max-height: none;
        border-radius: 20px;
    }
    .kkai-fab { right: 16px; bottom: 16px; }
}

/* 头部 */
.kkai-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(59,130,246,0.35), rgba(139,92,246,0.35));
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.kkai-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    flex-shrink: 0;
}

.kkai-header-info { flex: 1; min-width: 0; }
.kkai-header-title {
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.kkai-header-title span {
    background: rgba(255,255,255,0.15);
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
}
.kkai-header-subtitle {
    color: rgba(226,232,240,0.75);
    font-size: 12px;
    margin-top: 3px;
}

.kkai-header-actions { display: flex; gap: 6px; }
.kkai-header-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: none;
    background: rgba(255,255,255,0.08);
    color: #e2e8f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.kkai-header-btn:hover { background: rgba(255,255,255,0.18); }
.kkai-header-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* 消息区 */
.kkai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: #475569 #1e293b;
}
.kkai-messages::-webkit-scrollbar { width: 6px; }
.kkai-messages::-webkit-scrollbar-track { background: transparent; }
.kkai-messages::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }

.kkai-date-line {
    align-self: center;
    font-size: 11px;
    color: #94a3b8;
    background: rgba(255,255,255,0.06);
    padding: 3px 12px;
    border-radius: 999px;
    margin: 4px 0;
}

/* 单条消息 */
.kkai-msg { display: flex; gap: 10px; max-width: 92%; }
.kkai-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.kkai-msg.ai { align-self: flex-start; }

.kkai-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}
.kkai-msg.user .kkai-msg-avatar { background: linear-gradient(135deg, #ec4899, #8b5cf6); }
.kkai-msg.ai .kkai-msg-avatar { background: linear-gradient(135deg, #3b82f6, #8b5cf6); }

.kkai-bubble {
    padding: 12px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.kkai-msg.user .kkai-bubble {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff;
    border-bottom-right-radius: 6px;
}
.kkai-msg.ai .kkai-bubble {
    background: rgba(30, 41, 59, 0.95);
    color: #e2e8f0;
    border: 1px solid rgba(255,255,255,0.06);
    border-bottom-left-radius: 6px;
}

.kkai-msg-meta {
    font-size: 10px;
    color: #64748b;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.kkai-msg.user .kkai-msg-meta { justify-content: flex-end; }
.kkai-msg-status {
    width: 12px;
    height: 12px;
    display: inline-flex;
}
.kkai-msg-status.sent svg { fill: #94a3b8; }
.kkai-msg-status.read svg { fill: #60a5fa; }

/* 文件卡片 */
.kkai-file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15,23,42,0.7);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 10px 12px;
    margin-top: 6px;
    max-width: 260px;
}
.kkai-file-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(59,130,246,0.18);
    color: #60a5fa;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.kkai-file-icon svg { width: 20px; height: 20px; fill: currentColor; }
.kkai-file-info { min-width: 0; flex: 1; }
.kkai-file-name {
    font-size: 13px;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kkai-file-size {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

/* 快速操作 chip */
.kkai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 16px 10px;
    flex-shrink: 0;
}
.kkai-chip {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(59,130,246,0.12);
    border: 1px solid rgba(59,130,246,0.25);
    color: #93c5fd;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}
.kkai-chip:hover {
    background: rgba(59,130,246,0.25);
    color: #bfdbfe;
    transform: translateY(-1px);
}

/* 输入区 */
.kkai-input-area {
    padding: 12px 14px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(15,23,42,0.6);
    flex-shrink: 0;
}

.kkai-input-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.kkai-tool-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: none;
    background: rgba(255,255,255,0.06);
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.kkai-tool-btn:hover { background: rgba(255,255,255,0.14); color: #e2e8f0; }
.kkai-tool-btn svg { width: 18px; height: 18px; fill: currentColor; }

.kkai-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(100,116,139,0.35);
    border-radius: 18px;
    padding: 8px 8px 8px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.kkai-input-wrap:focus-within {
    border-color: rgba(59,130,246,0.6);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.kkai-input {
    flex: 1;
    border: none;
    background: transparent;
    color: #e2e8f0;
    font-size: 14px;
    line-height: 1.5;
    max-height: 120px;
    min-height: 24px;
    resize: none;
    outline: none;
    font-family: inherit;
    padding: 4px 0;
}
.kkai-input::placeholder { color: #64748b; }

.kkai-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, opacity 0.15s;
    flex-shrink: 0;
}
.kkai-send-btn:hover { transform: scale(1.05); }
.kkai-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.kkai-send-btn svg { width: 18px; height: 18px; fill: currentColor; }

.kkai-file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin: 0 14px 8px;
    background: rgba(59,130,246,0.1);
    border: 1px solid rgba(59,130,246,0.2);
    border-radius: 10px;
    font-size: 12px;
    color: #93c5fd;
}
.kkai-file-preview button {
    margin-left: auto;
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

/* 邮件表单 */
.kkai-email-form {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(15,23,42,0.6);
}
.kkai-email-form h4 {
    color: #e2e8f0;
    font-size: 14px;
    margin: 0 0 10px;
    font-weight: 600;
}
.kkai-email-form input,
.kkai-email-form textarea {
    width: 100%;
    margin-bottom: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(100,116,139,0.35);
    background: rgba(30,41,59,0.7);
    color: #e2e8f0;
    font-size: 13px;
    outline: none;
    font-family: inherit;
}
.kkai-email-form input::placeholder,
.kkai-email-form textarea::placeholder { color: #64748b; }
.kkai-email-form input:focus,
.kkai-email-form textarea:focus { border-color: rgba(59,130,246,0.6); }
.kkai-email-form textarea { min-height: 70px; resize: vertical; }

.kkai-email-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.kkai-btn-primary {
    padding: 9px 16px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.kkai-btn-primary:hover { opacity: 0.92; }
.kkai-btn-secondary {
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid rgba(100,116,139,0.4);
    background: rgba(30,41,59,0.6);
    color: #e2e8f0;
    font-size: 13px;
    cursor: pointer;
}
.kkai-btn-secondary:hover { background: rgba(51,65,85,0.6); }

.kkai-toast {
    position: absolute;
    left: 50%;
    top: 58px;
    transform: translateX(-50%);
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 12px;
    color: #fff;
    background: rgba(15,23,42,0.95);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, top 0.25s;
    z-index: 10;
    max-width: 90%;
    text-align: center;
}
.kkai-toast.show { opacity: 1; top: 66px; }
.kkai-toast.success { border-color: rgba(34,197,94,0.4); color: #86efac; }
.kkai-toast.error { border-color: rgba(239,68,68,0.4); color: #fca5a5; }

/* 打字指示器 */
.kkai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
}
.kkai-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: kkai-typing-bounce 1.2s infinite ease-in-out;
}
.kkai-typing-dot:nth-child(1) { animation-delay: 0s; }
.kkai-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.kkai-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes kkai-typing-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}
