/* 前台 AI 智能客服 — 跟随当前风格主色（风格1 / 风格3 各自 :root 变量） */

.ai-cs-chat-panel {
    --ai-cs-primary: var(--primary-color, #3498db);
    --ai-cs-primary-light: var(--primary-light, var(--primary-color, #3498db));
    --ai-cs-primary-rgb: var(--primary-color-rgb, 52, 152, 219);
    --ai-cs-bg: #f5f8fc;
    --ai-cs-border: color-mix(in srgb, var(--ai-cs-primary) 22%, #ffffff);
    --ai-cs-text: var(--text-primary, var(--text-color, #2c3e50));
    --ai-cs-muted: #8a97a8;
    --ai-cs-header-bg: var(--gradient-1, var(--gradient-accent, linear-gradient(135deg, var(--ai-cs-primary), var(--ai-cs-primary-light))));

    position: fixed;
    right: 22px;
    bottom: 96px;
    width: 380px;
    max-width: calc(100vw - 28px);
    height: 560px;
    max-height: calc(100vh - 112px);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 18px;
    background: #fff;
    border: 1px solid var(--ai-cs-border);
    box-shadow:
        0 18px 48px rgba(var(--ai-cs-primary-rgb), 0.16),
        0 2px 8px rgba(var(--ai-cs-primary-rgb), 0.06);
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.ai-cs-chat-panel.ai-cs-chat-panel--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.ai-cs-chat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 14px;
    background: var(--ai-cs-header-bg);
    color: #fff;
}

.ai-cs-chat-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.ai-cs-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    flex-shrink: 0;
}

.ai-cs-chat-brand-text {
    min-width: 0;
}

.ai-cs-chat-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.3;
}

.ai-cs-chat-status {
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.78);
}

.ai-cs-chat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #7ddea2;
    box-shadow: 0 0 0 3px rgba(125, 222, 162, 0.25);
}

.ai-cs-chat-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.ai-cs-chat-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.ai-cs-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 16px;
    background:
        radial-gradient(ellipse at top right, rgba(var(--ai-cs-primary-rgb), 0.07), transparent 55%),
        var(--ai-cs-bg);
}

.ai-cs-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-cs-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(var(--ai-cs-primary-rgb), 0.22);
    border-radius: 999px;
}

.ai-cs-chat-msg {
    display: flex;
    margin-bottom: 14px;
    max-width: 86%;
    animation: aiCsMsgIn 0.22s ease;
}

@keyframes aiCsMsgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-cs-chat-msg-user {
    margin-left: auto;
    justify-content: flex-end;
}

.ai-cs-chat-msg-bot {
    margin-right: auto;
    justify-content: flex-start;
}

.ai-cs-chat-msg-body {
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.65;
    font-size: 14px;
    color: var(--ai-cs-text);
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(var(--ai-cs-primary-rgb), 0.05);
}

.ai-cs-chat-msg-user .ai-cs-chat-msg-body {
    background: var(--ai-cs-header-bg);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.ai-cs-chat-msg-bot .ai-cs-chat-msg-body {
    background: #fff;
    border: 1px solid var(--ai-cs-border);
    border-bottom-left-radius: 6px;
}

.ai-cs-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 18px;
    padding: 0 2px;
}

.ai-cs-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9aa8ba;
    display: block;
    animation: aiCsTyping 1.2s infinite ease-in-out;
}

.ai-cs-typing i:nth-child(2) {
    animation-delay: 0.15s;
}

.ai-cs-typing i:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes aiCsTyping {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

.ai-cs-chat-input-wrap {
    flex-shrink: 0;
    padding: 12px 14px 14px;
    background: #fff;
    border-top: 1px solid var(--ai-cs-border);
}

.ai-cs-chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 12px;
    border: 1px solid var(--ai-cs-border);
    border-radius: 14px;
    background: #f8fafc;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.ai-cs-chat-composer:focus-within {
    background: #fff;
    border-color: var(--ai-cs-primary);
    box-shadow: 0 0 0 3px rgba(var(--ai-cs-primary-rgb), 0.12);
}

.ai-cs-chat-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ai-cs-text);
    max-height: 96px;
    padding: 6px 0;
    font-family: inherit;
}

.ai-cs-chat-input::placeholder {
    color: #a0aec0;
}

.ai-cs-chat-send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 11px;
    background: var(--ai-cs-header-bg);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.ai-cs-chat-send:hover {
    transform: translateY(-1px);
}

.ai-cs-chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.ai-cs-chat-footer {
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ai-cs-chat-clear {
    border: none;
    background: transparent;
    color: var(--ai-cs-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 0;
}

.ai-cs-chat-clear:hover {
    color: var(--ai-cs-primary);
}

.ai-cs-chat-hint {
    font-size: 12px;
    color: #b0bac8;
}

/* 风格主题覆盖（比 :has 更稳） */
.ai-cs-chat-panel.ai-cs-theme-style1 {
    /* 与顶部导航 .common-header-main 一致：#1a237e / #0d47a1 */
    --ai-cs-primary: var(--nav-bg-solid, #1a237e);
    --ai-cs-primary-light: #0d47a1;
    --ai-cs-primary-rgb: 26, 35, 126;
    --ai-cs-border: rgba(26, 35, 126, 0.28);
    --ai-cs-header-bg: var(--nav-bg, linear-gradient(135deg, #1a237e, #0d47a1));
}

.ai-cs-chat-panel.ai-cs-theme-style3 {
    --ai-cs-primary: var(--primary-color, #223a5e);
    --ai-cs-primary-light: var(--primary-light, #3a5485);
    --ai-cs-primary-rgb: 34, 58, 94;
    --ai-cs-border: rgba(34, 58, 94, 0.18);
    --ai-cs-header-bg: var(--gradient-accent, linear-gradient(135deg, #223a5e, #3a5485));
}

/* 风格3：补齐 rgb，保证阴影/描边正常（风格1自带 --primary-color-rgb） */
body:has(.common3-float-button-group) .ai-cs-chat-panel,
body:has(.common3-floating-buttons) .ai-cs-chat-panel {
    --ai-cs-primary-rgb: 34, 58, 94;
    --ai-cs-border: rgba(34, 58, 94, 0.16);
}

@media screen and (max-width: 768px) {
    .ai-cs-chat-panel {
        right: 10px;
        left: 10px;
        width: auto;
        bottom: 88px;
        height: min(68vh, 560px);
        border-radius: 16px;
    }
}

/* 不支持 color-mix 时的边框兜底 */
@supports not (border-color: color-mix(in srgb, #000 20%, #fff)) {
    .ai-cs-chat-panel {
        border-color: rgba(var(--ai-cs-primary-rgb), 0.22);
    }

    .ai-cs-chat-msg-bot .ai-cs-chat-msg-body,
    .ai-cs-chat-input-wrap,
    .ai-cs-chat-composer {
        border-color: rgba(var(--ai-cs-primary-rgb), 0.18);
    }
}
