/* 智能客服页面样式 - 无外框，输入框悬浮底部 */

.customer-service-body {
    overflow: hidden;
    height: 100vh;
}

.customer-service-page {
    padding-top: var(--header-height);
    height: calc(100vh - var(--header-height));
    min-height: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% 0%, rgba(17, 214, 187, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(17, 214, 187, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse 50% 30% at 0% 80%, rgba(17, 214, 187, 0.04) 0%, transparent 50%),
        linear-gradient(180deg, #fafcfc 0%, #f5faf9 30%, #f0f7f6 60%, #ffffff 100%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 聊天区域 - 占满除头部外的可视高度，带滚动条 */
.cs-chat-section {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.cs-chat-messages {
    padding: 2rem 1.5rem 160px 1.5rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.cs-chat-welcome {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-light);
}

.cs-welcome-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.cs-welcome-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.cs-welcome-hint {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

/* 消息气泡 - 带头像 */
.cs-msg {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    animation: cs-msg-in 0.35s ease;
}

@keyframes cs-msg-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.cs-msg.user {
    flex-direction: row-reverse;
}

.cs-msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    overflow: hidden;
}

.cs-msg.assistant .cs-msg-avatar {
    background: transparent;
}

.cs-msg.assistant .cs-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cs-msg.user .cs-msg-avatar {
    background: linear-gradient(135deg, #e0e0e0 0%, #bdbdbd 100%);
    color: #fff;
}

.cs-msg.user .cs-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cs-msg-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: calc(100% - 52px);
}

.cs-msg.user .cs-msg-body {
    align-items: flex-end;
}

.cs-msg-bubble {
    max-width: 100%;
    padding: 0.85rem 1.15rem;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.65;
    word-break: break-word;
}

.cs-msg.user .cs-msg-bubble {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.cs-msg.assistant .cs-msg-bubble {
    background: var(--bg-gray);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

/* AI 回复 Markdown 样式 */
.cs-msg-bubble.cs-markdown {
    padding: 1rem 1.25rem;
}

/* 欢迎消息排版 - 宽松舒适 */
.cs-msg-bubble:has(.cs-welcome-block) {
    padding: 1.5rem 1.5rem;
}

.cs-welcome-block {
    line-height: 1.75;
}

.cs-welcome-block .cs-welcome-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1A1A1A;
    margin: 0 0 0.75rem;
    letter-spacing: 0.02em;
}

.cs-welcome-block .cs-welcome-subtitle {
    font-size: 0.95rem;
    color: var(--text-light);
    margin: 0 0 1.5rem;
    line-height: 1.7;
}

.cs-welcome-block .cs-welcome-greeting {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-color);
    margin: 0 0 1rem;
}

.cs-welcome-block .cs-welcome-intro {
    font-size: 0.95rem;
    color: var(--text-color);
    margin: 0 0 1.25rem;
    line-height: 1.8;
}

.cs-welcome-block .cs-welcome-hint {
    font-size: 0.85rem;
    color: var(--text-lighter);
    margin: 0;
}

/* 欢迎消息内嵌二维码 */
.cs-welcome-qr {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.cs-welcome-qr-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.cs-welcome-qr-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.cs-welcome-qr .cs-welcome-qr-item img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 6px;
}

.cs-welcome-qr-item span {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.35rem;
}

/* PC端不显示欢迎消息内二维码（右下角已有悬浮二维码） */
@media (min-width: 769px) {
    .cs-welcome-qr {
        display: none;
    }
}

/* 移动端隐藏「右下角可扫码」提示，二维码在消息内展示 */
@media (max-width: 768px) {
    .cs-welcome-hint-pc {
        display: none;
    }

    .cs-welcome-qr .cs-welcome-qr-item img {
        width: 56px;
        height: 56px;
    }

    .cs-welcome-qr-item span {
        font-size: 0.75rem;
    }
}

/* 移动端二维码弹层 */
.cs-qr-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
}

.cs-qr-modal.active {
    display: block;
}

.cs-qr-modal-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
}

.cs-qr-modal-content {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 280px;
    padding: 24px;
    background: #fff;
    border-radius: 16px;
    text-align: center;
}

.cs-qr-modal-close {
    position: absolute;
    right: 12px;
    top: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: #f0f0f0;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    color: #666;
    cursor: pointer;
}

.cs-qr-modal-title {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 16px;
}

.cs-qr-modal-img-wrap {
    padding: 12px;
    background: #fff;
    border-radius: 12px;
}

.cs-qr-modal-img-wrap img {
    width: 200px;
    height: 200px;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

.cs-qr-modal-hint {
    margin-top: 12px;
    font-size: 14px;
    color: var(--primary-color);
    font-weight: 500;
}

/* PC端不显示弹层（右下角已有悬浮二维码） */
@media (min-width: 769px) {
    .cs-qr-modal {
        display: none !important;
    }
}

.cs-msg-bubble.cs-markdown h1,
.cs-msg-bubble.cs-markdown h2,
.cs-msg-bubble.cs-markdown h3,
.cs-msg-bubble.cs-markdown h4 {
    margin: 1em 0 0.5em;
    font-weight: 600;
    line-height: 1.3;
}

.cs-msg-bubble.cs-markdown h1:first-child,
.cs-msg-bubble.cs-markdown h2:first-child,
.cs-msg-bubble.cs-markdown h3:first-child,
.cs-msg-bubble.cs-markdown h4:first-child {
    margin-top: 0;
}

.cs-msg-bubble.cs-markdown h3 { font-size: 1rem; }
.cs-msg-bubble.cs-markdown h4 { font-size: 0.95rem; }

.cs-msg-bubble.cs-markdown p {
    margin: 0.5em 0;
}

.cs-msg-bubble.cs-markdown p:first-child { margin-top: 0; }
.cs-msg-bubble.cs-markdown p:last-child { margin-bottom: 0; }

.cs-msg-bubble.cs-markdown ul,
.cs-msg-bubble.cs-markdown ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.cs-msg-bubble.cs-markdown li {
    margin: 0.25em 0;
}

.cs-msg-bubble.cs-markdown strong {
    font-weight: 600;
}

.cs-msg-bubble.cs-markdown a {
    color: var(--primary-color);
    text-decoration: none;
}

.cs-msg-bubble.cs-markdown a:hover {
    text-decoration: underline;
}

.cs-msg-bubble.cs-markdown img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 0.5em 0;
    display: block;
}

.cs-msg-bubble.cs-markdown code {
    background: rgba(0,0,0,0.06);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
}

.cs-msg-bubble.cs-markdown pre {
    background: rgba(0,0,0,0.06);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.cs-msg-bubble.cs-markdown pre code {
    background: none;
    padding: 0;
}

/* PC端右下角悬浮二维码 */
.cs-float-qr {
    display: none;
}

@media (min-width: 769px) {
    .cs-float-qr {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        position: fixed;
        right: 1.5rem;
        bottom: 100px;
        z-index: 100;
    }

    .cs-float-qr-item {
        background: #fff;
        border-radius: 12px;
        padding: 0.85rem 1rem;
        text-align: center;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        border: 1px solid var(--border-color);
        width: 140px;
    }

    .cs-float-qr-item img {
        width: 100px;
        height: 100px;
        display: block;
        margin: 0 auto 0.5rem;
        border-radius: 6px;
        object-fit: contain;
    }

    .cs-float-qr-item h4 {
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-color);
        margin-bottom: 0.2rem;
    }

    .cs-float-qr-item p {
        font-size: 0.7rem;
        color: var(--text-lighter);
        margin: 0;
    }
}

.cs-msg-time {
    font-size: 0.7rem;
    color: var(--text-lighter);
    margin-top: 0.35rem;
    padding: 0 2px;
}

.cs-msg.typing .cs-msg-bubble {
    display: flex;
    gap: 4px;
    padding: 1rem 1.25rem;
}

.cs-msg-dot {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: cs-dot-bounce 1.4s ease-in-out infinite;
}

.cs-msg-dot:nth-child(2) { animation-delay: 0.2s; }
.cs-msg-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes cs-dot-bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1.2); opacity: 1; }
}

/* 输入区域 - 透明悬浮底部 */
.cs-chat-input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem 1.5rem 1.25rem;
    background: transparent;
}

.cs-input-inner {
    max-width: 900px;
    margin: 0 auto;
}

.cs-input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background: var(--bg-gray);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
}

.cs-input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(17, 214, 187, 0.2);
}

#chatInput {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 0.5rem 0;
}

#chatInput:focus {
    outline: none;
}

.cs-send-btn {
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: #fff;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.cs-send-btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.cs-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* 移动端适配 */
@media (max-width: 768px) {
    .customer-service-page {
        padding-top: var(--header-height);
    }


    .cs-chat-messages {
        padding: 1.25rem 1rem 140px 1rem;
    }

    .cs-msg-avatar {
        width: 34px;
        height: 34px;
        font-size: 0.95rem;
    }

    .cs-msg-body {
        max-width: calc(100% - 44px);
    }

    .cs-msg-bubble {
        max-width: 100%;
    }

    .cs-chat-input-area {
        padding: 0.75rem 1rem 1rem;
    }

    /* 移动端输入框默认更高，提示用户可换行 */
    #chatInput {
        min-height: 52px;
    }

    .cs-welcome-block .cs-welcome-title {
        font-size: 1.2rem;
    }
}
