/* ============================================================
   固百力 访客聊天挂件（参考 b8x 客服风格，作用域限定 #gblChat）
   ============================================================ */
#gblChat {
    --gc-primary: #003059;
    --gc-primary-2: #023A6C;
    --gc-accent: #0081FF;
    --gc-bubble-mine: #5ce85c;
    --gc-bg: #f6f6f6;
    --gc-white: #ffffff;
    --gc-text: #333333;
    --gc-text-2: #666666;
    --gc-text-3: #999999;
    --gc-red: #ee0a24;
    --gc-shadow: 0 10px 30px rgba(0, 48, 89, .18);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    z-index: 99998;
}

#gblChat .gbl-chat-hide { display: none !important; }

/* ---------- 悬浮按钮 ---------- */
#gblChat .gbl-chat-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--amber-500);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(0, 48, 89, .35);
    transition: transform .18s ease, box-shadow .18s ease;
    z-index: 99999;
    padding: 0;
}
#gblChat .gbl-chat-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0, 48, 89, .45);
}
#gblChat .gbl-chat-launcher svg { width: 26px; height: 26px; }

#gblChat .gbl-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--gc-red);
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    font-weight: 600;
}

/* ---------- 面板 ---------- */
#gblChat .gbl-chat-panel {
    position: fixed;
    right: 20px;
    bottom: 88px;
    width: 372px;
    max-width: calc(100vw - 20px);
    height: 580px;
    max-height: calc(100vh - 110px);
    background: var(--gc-bg);
    border-radius: 10px;
    box-shadow: var(--gc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
}

/* ---------- 头部 ---------- */
#gblChat .gbl-chat-header {
    display: flex;
    align-items: center;
    height: 56px;
    padding: 0 12px;
    background: var(--gc-primary);
    color: #fff;
    flex-shrink: 0;
}
#gblChat .gbl-chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(255, 255, 255, .15);
    flex-shrink: 0;
}
#gblChat .gbl-chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
#gblChat .gbl-chat-header-info {
    margin-left: 10px;
    min-width: 0;
    flex: 1;
}
#gblChat .gbl-chat-header-username {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#gblChat .gbl-chat-header-status {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: rgba(255, 255, 255, .75);
    margin-top: 1px;
}
#gblChat .gbl-chat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .4);
    margin-right: 5px;
    flex-shrink: 0;
}
#gblChat .gbl-chat-dot.online { background: #3ee06f; }

#gblChat .gbl-chat-header-actions {
    display: flex;
    align-items: center;
}
#gblChat .gbl-chat-head-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, .85);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 0;
    margin-left: 2px;
}
#gblChat .gbl-chat-head-btn:hover { background: rgba(255, 255, 255, .14); }
#gblChat .gbl-chat-head-btn.muted { color: rgba(255, 255, 255, .35); }

/* ---------- 消息区 ---------- */
#gblChat .gbl-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    background: var(--gc-bg);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
#gblChat .gbl-chat-empty {
    text-align: center;
    color: var(--gc-text-3);
    font-size: 13px;
    padding: 40px 10px;
}
#gblChat .gbl-chat-notice {
    text-align: center;
    font-size: 12px;
    color: var(--gc-text-3);
    margin: 10px 0;
}

#gblChat .gbl-chat-msg {
    display: flex;
    align-items: flex-start;
    margin-bottom: 14px;
}
#gblChat .gbl-chat-msg.mine { justify-content: flex-end; }

#gblChat .gbl-chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #e5e5e5;
}
#gblChat .gbl-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#gblChat .gbl-chat-bubble {
    max-width: 72%;
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}
#gblChat .gbl-chat-msg.theirs .gbl-chat-bubble {
    background: var(--gc-white);
    color: var(--gc-text);
    margin-left: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
#gblChat .gbl-chat-msg.mine .gbl-chat-bubble {
    background: var(--gc-bubble-mine);
    color: #10310f;
    margin-right: 10px;
}
#gblChat .gbl-chat-msg.is-pending .gbl-chat-bubble { opacity: .6; }

#gblChat .gbl-chat-bubble.is-image {
    padding: 4px;
    background: var(--gc-white);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
#gblChat .gbl-chat-bubble.is-image img {
    max-width: 180px;
    max-height: 220px;
    border-radius: 4px;
    display: block;
    cursor: zoom-in;
}

#gblChat .gbl-chat-file {
    display: flex;
    align-items: center;
    color: var(--gc-accent);
    text-decoration: none;
    font-size: 13px;
}
#gblChat .gbl-chat-file-icon { margin-right: 6px; font-size: 16px; }
#gblChat .gbl-chat-file-name { word-break: break-all; }
#gblChat .gbl-chat-msg.mine .gbl-chat-file { color: #0b5a0b; }

/* ---------- 正在输入 ---------- */
#gblChat .gbl-chat-typing {
    display: flex;
    align-items: center;
    background: var(--gc-white);
    border-radius: 6px;
    padding: 10px 12px;
    width: fit-content;
    margin-bottom: 12px;
    margin-left: 44px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
#gblChat .gbl-chat-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #bdbdbd;
    margin-right: 4px;
    animation: gblChatBlink 1.2s infinite;
}
#gblChat .gbl-chat-typing i:nth-child(2) { animation-delay: .2s; }
#gblChat .gbl-chat-typing i:nth-child(3) { animation-delay: .4s; }
#gblChat .gbl-chat-typing span { font-size: 12px; color: var(--gc-text-3); margin-left: 4px; }
@keyframes gblChatBlink {
    0%, 80%, 100% { opacity: .3; }
    40% { opacity: 1; }
}

/* ---------- 快捷语 ---------- */
#gblChat .gbl-chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px 0;
    background: var(--gc-bg);
    flex-shrink: 0;
}
#gblChat .gbl-chat-quick:empty { padding: 0; }
#gblChat .gbl-chat-quick button {
    border: 1px solid #e0e0e0;
    background: var(--gc-white);
    color: var(--gc-text-2);
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 14px;
    cursor: pointer;
    transition: all .15s ease;
}
#gblChat .gbl-chat-quick button:hover {
    border-color: var(--gc-accent);
    color: var(--gc-accent);
}

/* ---------- 底部输入 ---------- */
#gblChat .gbl-chat-footer {
    background: var(--gc-white);
    border-top: 1px solid #eeeeee;
    flex-shrink: 0;
}
#gblChat .gbl-chat-toolbar {
    display: flex;
    align-items: center;
    padding: 6px 10px 0;
}
#gblChat .gbl-chat-tool-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--gc-text-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 0;
    margin-right: 4px;
}
#gblChat .gbl-chat-tool-btn:hover { background: #f0f0f0; color: var(--gc-text); }
#gblChat .gbl-chat-tool-btn:disabled { color: #ccc; cursor: not-allowed; }

#gblChat .gbl-chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 6px 10px 10px;
}
#gblChat .gbl-chat-input {
    flex: 1;
    border: none;
    resize: none;
    outline: none;
    font-size: 14px;
    line-height: 1.45;
    padding: 7px 4px;
    max-height: 90px;
    background: transparent;
    color: var(--gc-text);
    font-family: inherit;
}
#gblChat .gbl-chat-input:disabled { color: var(--gc-text-3); }
#gblChat .gbl-chat-send {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 6px;
    background: var(--gc-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 8px;
    transition: background .15s ease;
}
#gblChat .gbl-chat-send:hover { background: var(--gc-primary-2); }
#gblChat .gbl-chat-send:disabled { background: #b9c6d3; cursor: not-allowed; }

/* ---------- 表情面板 ---------- */
#gblChat .gbl-chat-emoji-picker {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 118px;
    height: 200px;
    background: var(--gc-white);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .16);
    padding: 10px;
    overflow-y: auto;
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    z-index: 5;
}
#gblChat .gbl-chat-emoji-picker.open { display: grid; }
#gblChat .gbl-chat-emoji-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    font-size: 22px;
    border-radius: 6px;
    cursor: pointer;
    transition: background .12s ease;
    user-select: none;
}
#gblChat .gbl-chat-emoji-item:hover { background: #f0f0f0; }

/* ---------- 底部提示 ---------- */
#gblChat .gbl-chat-footer-tip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: 11px;
    color: var(--gc-text-3);
    background: var(--gc-bg);
    flex-shrink: 0;
}
#gblChat .gbl-chat-footer-tip a {
    color: var(--gc-accent);
    text-decoration: none;
}

/* ---------- 图片预览 ---------- */
#gblChat .gbl-chat-image-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
}
#gblChat .gbl-chat-image-modal-content {
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 4px;
}
#gblChat .gbl-chat-image-modal-close {
    position: absolute;
    top: 16px;
    right: 24px;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
}

/* ---------- 移动端 ---------- */
@media (max-width: 480px) {
    body.gbl-chat-open { overflow: hidden; }
    #gblChat .gbl-chat-panel {
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }
    #gblChat .gbl-chat-footer-tip {
        padding-bottom: calc(6px + env(safe-area-inset-bottom));
    }
    #gblChat .gbl-chat-launcher {
        right: 16px;
        bottom: 16px;
    }
    #gblChat .gbl-chat-emoji-picker { grid-template-columns: repeat(7, 1fr); }
}
