.chat-button {
    position: fixed;
    bottom: 44px;
    right: 20px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.34), transparent 28%),
        linear-gradient(135deg, #7b6ee8 0%, #6f63db 52%, #4d79ff 100%);
    box-shadow: 0 14px 30px rgba(103, 93, 219, 0.28);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    border: 0;
    outline: none;
}

.chat-button::before {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(109, 97, 219, 0.3) 0%, rgba(77, 121, 255, 0.22) 48%, transparent 70%);
    animation: chatHalo 2.2s ease-out infinite;
    pointer-events: none;
    z-index: -1;
}

.chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 34px rgba(103, 93, 219, 0.42);
}

.chat-button:active {
    transform: scale(0.95);
}

.chat-button-tip {
    position: absolute;
    left: 50%;
    top: calc(100% + 8px);
    transform: translateX(-50%);
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.56);
    border-radius: 8px;
    color: #ffffff;
    background: linear-gradient(135deg, #6f63db 0%, #7b6ee8 62%, #4d79ff 100%);
    box-shadow: 0 12px 24px rgba(103, 93, 219, 0.28);
    white-space: nowrap;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
}

.chat-icon-svg {
    width: auto;
    height: auto;
    color: white;
    transform: none;
    font-size: 26px;
    line-height: 1;
}

.chat-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #fff;
    box-shadow: 0 8px 16px rgba(239, 68, 68, 0.32);
}

.chat-badge.show {
    display: flex;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(13, 107, 96, 0.42);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(13, 107, 96, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(13, 107, 96, 0);
    }
}

@keyframes chatHalo {
    0% {
        opacity: 0.72;
        transform: scale(0.86);
    }
    70% {
        opacity: 0;
        transform: scale(1.45);
    }
    100% {
        opacity: 0;
        transform: scale(1.45);
    }
}

.chat-button.has-notification {
    animation: pulse 2s infinite;
}

.chat-button.has-notification .chat-icon-svg {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px) rotate(-5deg); }
    50% { transform: translateX(3px) rotate(5deg); }
    75% { transform: translateX(-3px) rotate(-5deg); }
}

.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8, 30, 27, 0.44);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.chat-overlay.show {
    opacity: 1;
    visibility: visible;
}

.chat-window {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    background: #ffffff;
    border: 1px solid #dfe5e2;
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.show {
    transform: translateY(0);
}

.chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #6f63db 0%, #4d79ff 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding-top: max(16px, env(safe-area-inset-top));
}

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

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ed573;
    flex-shrink: 0;
}

.status-dot.offline {
    background: #ff6b6b;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: linear-gradient(180deg, #eef6ff 0%, #f6f9ff 100%);
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 14px;
}

.message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.message.visitor {
    align-items: flex-end;
}

.message.admin {
    align-items: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.visitor .message-bubble {
    background: linear-gradient(135deg, #4d79ff 0%, #6f63db 100%);
    color: #ffffff;
    border-bottom-right-radius: 3px;
    box-shadow: 0 10px 22px rgba(77, 121, 255, 0.22);
}

.message.admin .message-bubble {
    background: #f8fbff;
    color: #1d2b4f;
    border: 1px solid #dbe7ff;
    border-bottom-left-radius: 3px;
    box-shadow: 0 8px 18px rgba(77, 121, 255, 0.08);
}

.message-time {
    font-size: 11px;
    color: #7d8dad;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #dfe5e2;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    position: relative;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

#message-input {
    flex: 1;
    border: 1px solid #dfe5e2;
    border-radius: 8px;
    padding: 12px 18px;
    font-size: 16px;
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
}

#message-input:focus {
    border-color: #4d79ff;
    box-shadow: 0 0 0 3px rgba(77, 121, 255, 0.11);
}

.send-btn {
    padding: 12px 24px;
    background: #4d79ff;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    opacity: 1;
    background: #3868ef;
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-tool-btn {
    width: 42px;
    height: 42px;
    border: 1px solid #dfe5e2;
    border-radius: 8px;
    background: #f6f7f8;
    color: #17201d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    cursor: pointer;
    font-size: 17px;
}

.chat-tool-btn:hover {
    background: #eef2f0;
}

.emoji-panel {
    position: absolute;
    left: 16px;
    bottom: calc(100% + 8px);
    display: grid;
    grid-template-columns: repeat(5, 34px);
    gap: 6px;
    padding: 10px;
    border: 1px solid #dfe5e2;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 34px rgba(17, 32, 29, 0.12);
    z-index: 2;
}

.emoji-panel[hidden] {
    display: none;
}

.emoji-option {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
}

.emoji-option:hover {
    background: #f1f4f3;
}

.message-bubble.image-bubble {
    padding: 6px;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.chat-image-link {
    display: block;
    line-height: 0;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: zoom-in;
}

.chat-image {
    display: block;
    max-width: min(240px, 100%);
    max-height: 220px;
    border-radius: 8px;
    border: 1px solid #dfe5e2;
    object-fit: contain;
    background: #fff;
}

.chat-image-preview {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.chat-image-preview.show {
    display: flex;
}

.chat-image-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.62);
    backdrop-filter: blur(6px);
}

.chat-image-preview-panel {
    position: relative;
    z-index: 1;
    width: min(720px, 92vw);
    max-height: 86vh;
    padding: 14px;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid rgba(219, 231, 255, 0.9);
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.34);
}

.chat-image-preview-img {
    display: block;
    width: 100%;
    max-height: calc(86vh - 28px);
    object-fit: contain;
    border-radius: 6px;
    background: #f8fbff;
}

.chat-image-preview-close {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(219, 231, 255, 0.9);
    border-radius: 999px;
    background: #ffffff;
    color: #1d2b4f;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.2);
}

.chat-image-preview-close:hover {
    color: #4d79ff;
}

.chat-text-link {
    color: #4d79ff;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}

.message.visitor .chat-text-link {
    color: #ffffff;
}

.offline-notice {
    padding: 12px 16px;
    background: rgba(184, 138, 46, 0.12);
    color: #7a581d;
    font-size: 13px;
    text-align: center;
    flex-shrink: 0;
}

.offline-notice.hidden {
    display: none;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 8px;
    border-bottom-left-radius: 3px;
    border: 1px solid #dfe5e2;
    box-shadow: 0 8px 18px rgba(17, 32, 29, 0.05);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4d79ff;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

@media (min-width: 480px) {
    .chat-button {
        width: 58px;
        height: 58px;
        bottom: 48px;
        right: 24px;
    }

    .chat-icon-svg {
        font-size: 28px;
    }

    .chat-overlay {
        display: block;
    }

    .chat-window {
        position: fixed;
        bottom: 96px;
        right: 24px;
        left: auto;
        width: 360px;
        height: 520px;
        max-height: calc(100vh - 120px);
        border-radius: 8px;
        box-shadow: 0 18px 44px rgba(17, 32, 29, 0.12);
        transform: translateY(20px) scale(0.95);
        opacity: 0;
    }

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

    .chat-header {
        border-radius: 8px 8px 0 0;
        padding-top: 16px;
    }

    .chat-messages {
        border-radius: 0;
    }

    .chat-input-area {
        border-radius: 0 0 8px 8px;
        padding-bottom: 12px;
    }
}

@media (min-width: 768px) {
    .chat-button {
        bottom: 54px;
        right: 30px;
    }

    .chat-window {
        right: 30px;
        bottom: 100px;
    }
}

/* 喜得来·HG：客服组件适配绿色主题 */
.chat-button {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background:
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.5), transparent 28%),
        linear-gradient(135deg, #15803d 0%, #24b84f 58%, #7de38c 100%);
    box-shadow: 0 16px 34px rgba(21, 128, 61, 0.28);
}

.chat-button::before {
    border-radius: 22px;
    background: radial-gradient(circle, rgba(36, 184, 79, 0.26) 0%, rgba(125, 227, 140, 0.2) 48%, transparent 70%);
}

.chat-button:hover {
    box-shadow: 0 18px 38px rgba(21, 128, 61, 0.4);
}

.chat-button-tip {
    border-color: rgba(255, 255, 255, 0.64);
    border-radius: 999px;
    background: linear-gradient(135deg, #0f6b32 0%, #24b84f 100%);
    box-shadow: 0 12px 24px rgba(21, 128, 61, 0.26);
}

.chat-badge {
    border-color: #f2fbf4;
}

.chat-overlay {
    background: rgba(5, 24, 13, 0.46);
}

.chat-window {
    background: #f7fff8;
    border-color: rgba(166, 231, 181, 0.68);
}

.chat-header {
    background:
        radial-gradient(circle at 90% 0%, rgba(125, 227, 140, 0.28), transparent 36%),
        linear-gradient(135deg, #0f6b32 0%, #15803d 52%, #24b84f 100%);
}

.status-dot {
    background: #a7f3b6;
    box-shadow: 0 0 0 4px rgba(167, 243, 182, 0.18);
}

.chat-messages {
    background:
        radial-gradient(circle at 18% 0%, rgba(87, 221, 110, 0.12), transparent 28%),
        linear-gradient(180deg, #f2fbf4 0%, #f8fff9 100%);
}

.message.visitor .message-bubble {
    background: linear-gradient(135deg, #15803d 0%, #24b84f 100%);
    box-shadow: 0 10px 22px rgba(21, 128, 61, 0.2);
}

.message.admin .message-bubble {
    background: #ffffff;
    color: #0d2b18;
    border-color: rgba(166, 231, 181, 0.64);
    box-shadow: 0 8px 18px rgba(19, 77, 37, 0.08);
}

.message-time {
    color: #789183;
}

.chat-input-area {
    background: rgba(255, 255, 255, 0.94);
    border-top-color: rgba(166, 231, 181, 0.64);
}

#message-input {
    border-color: rgba(166, 231, 181, 0.8);
    border-radius: 12px;
    background: #ffffff;
    color: #0d2b18;
}

#message-input:focus {
    border-color: #24b84f;
    box-shadow: 0 0 0 3px rgba(36, 184, 79, 0.12);
}

.send-btn {
    border-radius: 12px;
    background: linear-gradient(135deg, #15803d, #24b84f);
    font-weight: 800;
}

.send-btn:hover {
    background: linear-gradient(135deg, #0f6b32, #24b84f);
}

.chat-tool-btn {
    border-color: rgba(166, 231, 181, 0.8);
    border-radius: 12px;
    background: #f2fbf4;
    color: #15803d;
}

.chat-tool-btn:hover,
.emoji-option:hover {
    background: #e3f8e8;
}

.emoji-panel {
    border-color: rgba(166, 231, 181, 0.72);
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 14px 34px rgba(19, 77, 37, 0.12);
}

.chat-image {
    border-color: rgba(166, 231, 181, 0.7);
}

html[data-yc-theme="fallback"] .chat-button {
    background:
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.28), transparent 28%),
        linear-gradient(135deg, #0f6b32 0%, #15803d 58%, #53df78 100%);
    color: #fff;
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.3), 0 0 24px rgba(83, 223, 120, 0.16);
}

html[data-yc-theme="fallback"] .chat-window {
    background: #07140d;
    border-color: rgba(140, 231, 159, 0.2);
}

html[data-yc-theme="fallback"] .chat-header {
    background:
        radial-gradient(circle at 90% 0%, rgba(83, 223, 120, 0.2), transparent 36%),
        linear-gradient(135deg, #082914 0%, #0f6b32 100%);
}

html[data-yc-theme="fallback"] .chat-messages {
    background:
        radial-gradient(circle at 18% 0%, rgba(83, 223, 120, 0.1), transparent 28%),
        linear-gradient(180deg, #07140d 0%, #0b1a12 100%);
}

html[data-yc-theme="fallback"] .message.admin .message-bubble {
    color: #eefbf1;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(140, 231, 159, 0.18);
}

html[data-yc-theme="fallback"] .chat-input-area {
    background: rgba(6, 16, 11, 0.96);
    border-top-color: rgba(140, 231, 159, 0.18);
}

html[data-yc-theme="fallback"] #message-input,
html[data-yc-theme="fallback"] .emoji-panel {
    color: #eefbf1;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(140, 231, 159, 0.2);
}

html[data-yc-theme="fallback"] .chat-tool-btn {
    color: #dfffe7;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(140, 231, 159, 0.2);
}
/* 调整：聊天输入栏元素垂直居中 */
.chat-input-area {
    align-items: center;
}

.chat-tool-btn,
.send-btn,
#message-input {
    height: 42px;
    min-height: 42px;
    box-sizing: border-box;
}

#message-input {
    padding-top: 0;
    padding-bottom: 0;
    line-height: 42px;
    overflow-y: hidden;
    display: block;
}

.send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 0;
    line-height: 1;
}

.chat-tool-btn {
    align-self: center;
}