/* ═══════════════════════════════════════════════════
   Rocket Consult — 前端组件样式
   实时对话 · 优雅动画 · 响应式
   ═══════════════════════════════════════════════════ */

:root {
    --jlc-primary: #6366f1;
    --jlc-secondary: #8b5cf6;
    --jlc-bg: #ffffff;
    --jlc-surface: #f8fafc;
    --jlc-text: #0f172a;
    --jlc-text-secondary: #64748b;
    --jlc-border: #e2e8f0;
    --jlc-radius: 18px;
    --jlc-shadow: 0 25px 70px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.04);
    --jlc-transition: cubic-bezier(.4,0,.2,1);
}

/* ───── 容器 ───── */
#jlc-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--jlc-text);
    -webkit-font-smoothing: antialiased;
}

/* ════════════════════ 悬浮气泡 ════════════════════ */
#jlc-bubble {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--jlc-primary), var(--jlc-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: transform .35s var(--jlc-transition), box-shadow .35s var(--jlc-transition);
    box-shadow: 0 8px 24px rgba(99,102,241,.4);
    z-index: 2;
}

#jlc-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 32px rgba(99,102,241,.5);
}

#jlc-bubble:active {
    transform: scale(.94);
}

.jlc-bubble-icon {
    font-size: 28px;
    line-height: 1;
    z-index: 2;
    transition: transform .3s var(--jlc-transition);
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.15));
}

#jlc-bubble:hover .jlc-bubble-icon {
    transform: scale(1.12) rotate(-5deg);
}

/* 状态指示圆点 */
#jlc-bubble::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
    z-index: 3;
    transition: background .3s;
    background: #cbd5e1;
}
#jlc-bubble.online::after {
    background: #10b981;
    box-shadow: 0 0 6px rgba(16,185,129,.5);
}

/* 脉冲动画 */
.jlc-bubble-pulse {
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    background: var(--jlc-primary);
    opacity: 0;
    animation: jlc-pulse 2.5s ease-out infinite;
    z-index: 0;
}

@keyframes jlc-pulse {
    0%   { transform: scale(.85); opacity: .45; }
    100% { transform: scale(1.45); opacity: 0; }
}

/* 未读徽章 */
.jlc-unread-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 11px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
    box-shadow: 0 2px 8px rgba(239,68,68,.4);
    animation: jlc-badge-pop .4s var(--jlc-transition);
}

@keyframes jlc-badge-pop {
    0%   { transform: scale(0); }
    60%  { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* ════════════════════ 聊天窗口 ════════════════════ */
/* 关键:聊天窗口直接用 position:fixed 定位到视口,
   不再用 position:absolute 跟随 #jlc-container.
   之前 absolute + 父容器 width:auto(≈62px) 会让窗口被父容器宽度截断成竖条,
   即便容器本身 fixed 也可能被外层 transform/filter 父级影响导致错位.
   这里固定 right:24px 与容器对齐,左/中模式覆盖 left 来切换. */
#jlc-chat-window {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 390px;
    max-height: 620px;
    border-radius: var(--jlc-radius);
    background: var(--jlc-bg);
    box-shadow: var(--jlc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: opacity .35s var(--jlc-transition), transform .35s var(--jlc-transition);
    z-index: 1;
}

#jlc-chat-window::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--jlc-radius);
    padding: 1px;
    background: linear-gradient(135deg, rgba(99,102,241,.2), rgba(139,92,246,.1), rgba(6,182,212,.1));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    z-index: 1;
}

#jlc-chat-window.jlc-hidden {
    opacity: 0;
    transform: scale(.9) translateY(15px);
    pointer-events: none;
}

#jlc-chat-window.jlc-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* ───── 头部 ───── */
.jlc-header {
    background: linear-gradient(135deg, var(--jlc-primary), var(--jlc-secondary));
    color: #fff;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.jlc-header::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,.06);
    pointer-events: none;
}

.jlc-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    z-index: 1;
}

.jlc-agent-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
    border: 2px solid rgba(255,255,255,.15);
    overflow: hidden;
}

.jlc-agent-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.jlc-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.jlc-header-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -.2px;
}

.jlc-header-subtitle {
    font-size: 12px;
    opacity: .88;
    display: flex;
    align-items: center;
    gap: 7px;
}

.jlc-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    flex-shrink: 0;
    transition: all .3s;
}
.jlc-status-dot.online {
    background: #10b981;
    box-shadow: 0 0 8px rgba(16,185,129,.5);
}

.jlc-close-btn {
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .25s;
    position: relative;
    z-index: 1;
    backdrop-filter: blur(4px);
}

.jlc-close-btn:hover {
    background: rgba(255,255,255,.28);
    transform: scale(1.08);
}

.jlc-close-btn svg {
    width: 18px;
    height: 18px;
}

/* ───── 预注册表单 ───── */
.jlc-pre-chat {
    padding: 44px 32px 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    flex: 1;
    background: linear-gradient(180deg, rgba(99,102,241,.04), rgba(99,102,241,.01));
}

.jlc-pre-chat-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 38px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(99,102,241,.12), 0 0 0 1px rgba(99,102,241,.06);
    animation: jlc-float 3s ease-in-out infinite;
    margin-bottom: 2px;
}

@keyframes jlc-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-8px); }
}

.jlc-pre-chat-form {
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.jlc-pre-chat-lead {
    color: var(--jlc-text-secondary);
    font-size: 15px;
    font-weight: 500;
    line-height: 1.5;
    margin: 0 0 6px;
}

.jlc-pre-chat input {
    width: 100%;
    padding: 14px 18px;
    border: 1.5px solid var(--jlc-border);
    border-radius: 14px;
    font-size: 14px;
    outline: none;
    transition: all .25s var(--jlc-transition);
    font-family: inherit;
    background: #fff;
    color: var(--jlc-text);
    box-shadow: 0 1px 2px rgba(0,0,0,.02);
}

.jlc-pre-chat input::placeholder {
    color: #94a3b8;
}

.jlc-pre-chat input:focus {
    border-color: var(--jlc-primary);
    box-shadow: 0 0 0 4px rgba(99,102,241,.1);
    background: #fff;
}

.jlc-pre-chat button {
    margin-top: 6px;
    padding: 14px 44px;
    background: linear-gradient(135deg, var(--jlc-primary), var(--jlc-secondary));
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all .25s var(--jlc-transition);
    font-family: inherit;
    box-shadow: 0 6px 20px rgba(99,102,241,.3);
    letter-spacing: .3px;
}

.jlc-pre-chat button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(99,102,241,.4);
}

.jlc-pre-chat button:active {
    transform: translateY(0) scale(.97);
}

/* 已登录用户信息 */
.jlc-pre-chat-logged {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
}
.jlc-user-avatar-wrap {
    position: relative;
    width: 62px;
    height: 62px;
}
.jlc-user-avatar-img {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--jlc-primary);
    box-shadow: 0 4px 12px rgba(99,102,241,.15);
}
.jlc-user-avatar-fallback {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--jlc-primary), var(--jlc-secondary));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
}
.jlc-user-avatar-fallback svg {
    stroke: #fff;
    flex-shrink: 0;
}
.jlc-user-info {
    text-align: center;
}
.jlc-user-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--jlc-text);
}
.jlc-user-hint {
    font-size: 12px;
    color: var(--jlc-text-secondary);
    margin-top: 3px;
}

/* ───── 消息区域 ───── */
.jlc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(99,102,241,.025), transparent 60%),
        #f8fafc;
    min-height: 300px;
    max-height: 440px;
    scroll-behavior: smooth;
    position: relative;
}

.jlc-messages-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 在线状态横幅 */
.jlc-status-banner {
    text-align: center;
    padding: 10px 16px;
    background: rgba(99,102,241,.05);
    margin: -8px -8px 4px;
    border-radius: 10px;
    font-size: 13px;
    color: var(--jlc-text-secondary);
}
.jlc-status-banner.offline {
    background: rgba(148,163,184,.08);
    color: #94a3b8;
}

/* 消息气泡 */
.jlc-msg {
    display: flex;
    gap: 0;
    animation: jlc-msg-in .35s var(--jlc-transition);
    position: relative;
}

@keyframes jlc-msg-in {
    0%   { opacity: 0; transform: translateY(10px) scale(.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.jlc-msg-visitor {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.jlc-msg-visitor .jlc-msg-body {
    background: linear-gradient(135deg, var(--jlc-primary), var(--jlc-secondary));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(99,102,241,.15);
}

.jlc-msg-agent {
    align-self: flex-start;
    flex-direction: row;
}
.jlc-msg-agent .jlc-msg-body {
    background: #fff;
    color: var(--jlc-text);
    border: 1px solid var(--jlc-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

/* 自动回复标识 */
.jlc-msg-agent.auto-reply .jlc-msg-body {
    border-style: dashed;
    border-color: rgba(99,102,241,.25);
    background: rgba(99,102,241,.02);
}

/* 消息内容容器 */
.jlc-msg-body {
    max-width: 78%;
    padding: 11px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    position: relative;
}

/* 消息头像 */
.jlc-msg-avatar {
    flex-shrink: 0;
    align-self: flex-end;
    margin: 0 8px;
}
.jlc-visitor-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--jlc-primary);
}
.jlc-visitor-avatar-fallback {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--jlc-primary), var(--jlc-secondary));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
}
.jlc-visitor-avatar-fallback svg {
    stroke: #fff;
    flex-shrink: 0;
}
.jlc-guest-avatar {
    background: linear-gradient(135deg, #a5b4fc, #6366f1) !important;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.2), 0 2px 6px rgba(99,102,241,.2);
}
.jlc-msg-agent-ava {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    overflow: hidden;
}

.jlc-msg-agent-kf-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.jlc-msg-system {
    display: block;
    align-self: center;
    background: rgba(148,163,184,.08);
    color: var(--jlc-text-secondary);
    font-size: 12px;
    padding: 5px 14px;
    text-align: center;
    max-width: 100%;
    border-radius: 16px;
}

.jlc-msg-time {
    font-size: 11px;
    opacity: .5;
    margin-top: 5px;
    display: block;
    font-weight: 500;
}

.jlc-msg-visitor .jlc-msg-time {
    text-align: right;
}

/* 打字指示器 */
.jlc-typing-indicator {
    padding: 10px 16px;
    font-size: 13px;
    color: var(--jlc-text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.jlc-typing-dots {
    display: inline-flex;
    gap: 4px;
}

.jlc-typing-dots i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--jlc-primary);
    animation: jlc-typing 1.4s ease-in-out infinite;
    opacity: .5;
}

.jlc-typing-dots i:nth-child(2) { animation-delay: .2s; }
.jlc-typing-dots i:nth-child(3) { animation-delay: .4s; }

@keyframes jlc-typing {
    0%, 60%, 100% { opacity: .25; transform: translateY(0); }
    30%           { opacity: 1; transform: translateY(-5px); }
}

/* ───── 输入区域 ───── */
.jlc-input-area {
    padding: 14px 18px 10px;
    border-top: 1px solid var(--jlc-border);
    background: var(--jlc-bg);
    flex-shrink: 0;
}

.jlc-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8fafc;
    border: 1.5px solid var(--jlc-border);
    border-radius: 14px;
    padding: 4px 4px 4px 16px;
    transition: all .25s var(--jlc-transition);
}

.jlc-input-wrap:focus-within {
    border-color: var(--jlc-primary);
    box-shadow: 0 0 0 4px rgba(99,102,241,.08);
    background: #fff;
}

.jlc-input-wrap textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 100px;
    padding: 8px 0;
    color: var(--jlc-text);
}

.jlc-input-wrap textarea::placeholder {
    color: #94a3b8;
}

.jlc-input-wrap button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--jlc-primary), var(--jlc-secondary));
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all .2s var(--jlc-transition);
    box-shadow: 0 2px 8px rgba(99,102,241,.2);
}

.jlc-input-wrap button:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 14px rgba(99,102,241,.3);
}

.jlc-input-wrap button:active {
    transform: scale(.94);
}

.jlc-input-wrap button svg {
    width: 20px;
    height: 20px;
}

.jlc-input-footer {
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
    padding-top: 6px;
}

/* 离线时输入区样式 */
.jlc-input-area.offline .jlc-input-wrap {
    border-color: #e2e8f0;
    opacity: .7;
}

.jlc-input-area.offline .jlc-input-footer {
    color: #f59e0b;
}

/* ───── 日期分隔线 ───── */
.jlc-date-divider {
    text-align: center;
    font-size: 12px;
    color: var(--jlc-text-secondary);
    padding: 10px 0;
    position: relative;
    font-weight: 500;
}

.jlc-date-divider::before,
.jlc-date-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: var(--jlc-border);
}

.jlc-date-divider::before { left: 0; }
.jlc-date-divider::after  { right: 0; }

/* ───── 工具类 ───── */
.jlc-hidden { display: none !important; }

/* 表单校验抖动 */
@keyframes jlc-shake {
    0%, 100% { transform: translateX(0); }
    20%  { transform: translateX(-8px); }
    40%  { transform: translateX(8px); }
    60%  { transform: translateX(-6px); }
    80%  { transform: translateX(6px); }
}
.jlc-shake {
    animation: jlc-shake .5s ease-in-out;
}

/* ───── 响应式 ───── */
@media (max-width: 480px) {
    #jlc-container {
        bottom: 16px;
        right: 12px;
    }

    /* 窄屏下窗口改为 fixed + left/right 撑满视口
       避免被 position:absolute + 父容器 width:auto 截断成竖条
       之前在 transform / overflow 父级下会渲染成 ~80px 宽
       ★ 新增 top:64px + 减掉 max-height:
         不让窗口撑到视口顶端,避免覆盖顶部导航栏的 hamburger 按钮 */
    #jlc-chat-window {
        position: fixed;
        top: 64px;
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 64px - 80px - 12px);
        bottom: 80px;
    }

    #jlc-bubble {
        width: 54px;
        height: 54px;
    }

    .jlc-bubble-icon {
        font-size: 24px;
    }

    /* left 模式:窗口从 bubble 左侧展开,贴左对齐
       注意:聊天窗口是 #jlc-container 的兄弟节点,不再用后代选择器 */
    #jlc-container.jlc-pos-left + #jlc-chat-window {
        left: 12px;
        right: 12px;
    }
}

/* ───── 右侧居中模式 ───── */
#jlc-container.jlc-pos-center {
    top: 50%;
    bottom: auto;
    /* 这里保留 transform: translateY(-50%) 让容器居中。
       聊天窗口已挪出容器,不会被这个 transform 影响 containing block。 */
    transform: translateY(-50%);
}

/* 聊天窗口作为 #jlc-container 的兄弟节点,用 ~ 选择器覆盖定位 */
#jlc-container.jlc-pos-center ~ #jlc-chat-window {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%) scale(1);
    transform-origin: center right;
}

#jlc-container.jlc-pos-center ~ #jlc-chat-window.jlc-hidden {
    transform: translateY(-50%) scale(.9) translateX(15px);
}

#jlc-container.jlc-pos-center ~ #jlc-chat-window.jlc-visible {
    transform: translateY(-50%) scale(1) translateX(0);
}

#jlc-container.jlc-pos-center.jlc-pos-left ~ #jlc-chat-window {
    transform-origin: center left;
}

/* 左侧模式:窗口固定在视口左侧,与气泡对齐(widht 屏幕下也生效)
   聊天窗口是兄弟节点,使用 ~ 选择器 */
#jlc-container.jlc-pos-left ~ #jlc-chat-window {
    right: auto;
    left: 24px;
    transform-origin: bottom left;
}

/* ───── 滚动条美化 ───── */
.jlc-messages::-webkit-scrollbar {
    width: 5px;
}

.jlc-messages::-webkit-scrollbar-track {
    background: transparent;
}

.jlc-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,.1);
    border-radius: 3px;
}

.jlc-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,.2);
}
