/* visitor chat */

        * { box-sizing: border-box; }
        html { height: 100%; background: #22c55e; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
        body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 12px; background: #22c55e; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
        .chat-wrap { display: flex; flex-direction: column; height: 100%; min-height: 100vh; min-height: 100dvh; background: #eef1f4; min-width: 0; overflow: hidden; }
        .chat-header { flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); background: #22c55e; color: #fff; }
        .chat-header-logo { width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; font-size: 16px; font-weight: 700; }
        .chat-header-logo.has-avatar { background-color: transparent; background-size: cover; background-position: center; background-repeat: no-repeat; }
        .chat-header-avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; display: block; }
        .chat-header-title { font-size: 16px; font-weight: 600; flex: 1; letter-spacing: .01em; }
        .chat-header-status { display: none; }
        .chat-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 10px 8px; background: #eef1f4; }
        .chat-body::-webkit-scrollbar { width: 6px; }
        .chat-body::-webkit-scrollbar-track { background: transparent; }
        .chat-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 3px; }
        .chat-body::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.28); }
        .chat-banner { background: linear-gradient(135deg, #e8fbef, #d3f5e0); border-radius: 10px; padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
        .chat-banner-top { display: flex; align-items: center; gap: 6px; }
        .chat-banner-brand { font-size: 14px; font-weight: 800; color: #25d366; }
        .chat-banner-mark { width: 18px; height: 18px; flex-shrink: 0; display: block; }
        .chat-banner-mark svg { width: 18px; height: 18px; display: block; }
        .chat-banner-title { font-size: 15px; font-weight: 800; color: #0f5132; margin: 5px 0 2px; }
        .chat-banner-sub { font-size: 11px; color: #3a6b4f; }
        .chat-banner-chips { display: flex; gap: 6px; margin-top: 12px; }
        .chat-banner-chip { flex: 1; background: #fff; border-radius: 8px; padding: 8px 3px; text-align: center; }
        .chat-banner-chip .ci { font-size: 15px; line-height: 1; display: flex; justify-content: center; align-items: center; min-height: 20px; }
        .chat-banner-chip .ci svg { width: 22px; height: 22px; display: block; }
        .chat-banner-chip .ct { font-size: 10px; color: #0f5132; font-weight: 600; margin-top: 3px; }
        .chat-banner-chip .cd { font-size: 9px; color: #6b8f7a; }
        .chat-banner-foot { background: #22c55e; color: #fff; border-radius: 20px; text-align: center; font-size: 11px; padding: 5px; margin-top: 10px; }
        .chat-footer { flex-shrink: 0; padding: 7px 10px; padding-bottom: max(7px, env(safe-area-inset-bottom)); background: #f2f3f5; border-top: none; display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 50px; }
        .chat-attach { display: none; align-items: center; gap: 8px; padding: 6px 10px; background: #fff; border-top: 1px solid #eee; }
        .chat-attach.show { display: flex; }
        .chat-attach img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: #f0f0f0; }
        .chat-attach-meta { flex: 1; min-width: 0; font-size: 12px; color: #666; }
        .chat-attach-clear { border: none; background: transparent; color: #999; font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
        .chat-footer #input { flex: 1; min-width: 0; height: 36px; padding: 0 14px; border: none; border-radius: 18px; font-size: 16px; outline: none; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
        .chat-footer #input::placeholder { color: #c4c4c4; font-size: 16px; }
        .chat-footer #btn-image { width: 36px; height: 36px; padding: 0; border: none; border-radius: 50%; background: #fff center/18px no-repeat; cursor: pointer; flex-shrink: 0; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
        .chat-footer #btn-image { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23888'%3E%3Cpath d='M21 19V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2zM8.5 13.5l2.5 3 3.5-4.5 4.5 6H5l3.5-4.5z'/%3E%3C/svg%3E"); }
        .chat-footer #btn-send { flex-shrink: 0; width: 36px; height: 36px; padding: 0; border: none; border-radius: 50%; background: #25d366; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: none; }
        .chat-footer #btn-send svg { width: 18px; height: 18px; fill: #fff; display: block; margin-left: 1px; }
        .chat-footer #btn-send:disabled { opacity: .6; cursor: not-allowed; }
        #messages { list-style: none; margin: 0; padding: 0; }
        #messages li { margin-bottom: 8px; }
        #messages li.msg-choice { display: none; }
        .sys-msg { background: #fff8d6; color: #8a6d00; font-size: 11px; text-align: center; max-width: 92%; margin: 8px auto; padding: 6px 10px; border-radius: 8px; }
        .sys-msg-connect { background: #fff9e1; color: #85702a; font-size: 11px; font-weight: 400; text-align: center; max-width: 92%; margin: 8px auto; padding: 6px 14px; border-radius: 10px; border: none; box-shadow: none; }
        .msg-row { clear: both; display: flex; flex-direction: column; }
        .msg-row.msg-me { align-items: flex-end; }
        .msg-row.msg-me .msg-bubble { display: inline-block; max-width: 92%; text-align: left; background: #dcf8c6; color: #222; padding: 7px 10px; border-radius: 8px; border-top-right-radius: 2px; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
        .msg-row.msg-other { align-items: flex-start; }
        .msg-row.msg-other .msg-bubble { display: inline-block; max-width: 94%; text-align: left; background: #fff; color: #222; padding: 7px 10px; border-radius: 8px; border-top-left-radius: 2px; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); border: 1px solid #ececec; }
        .msg-time { margin-top: 3px; font-size: 9px; line-height: 1.2; color: #999; }
        .msg-row.msg-me .msg-time { text-align: right; }
        .msg-row.msg-other .msg-time { text-align: left; }
        .code-row { display: flex; margin: 6px 0 14px; }
        .code-btn { display: inline-flex; align-items: center; gap: 8px; padding: 11px 22px; border: 1px solid #cfcfcf; border-radius: 50px; background: #fff; color: #111; font-size: 16px; font-weight: 600; font-family: Arial, Helvetica, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
        .code-btn.is-on { background: #0b9a38; border-color: #0b9a38; color: #fff; font-weight: 600; }
        .code-btn:disabled { opacity: 1; cursor: default; }
        .code-orb, .msg-code-orb { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; display: inline-block; vertical-align: -2px; background: radial-gradient(circle at 32% 28%, #e8ffb0 0%, #8dff3d 32%, #22c55e 62%, #128a38 100%); box-shadow: inset 0 -1px 2px rgba(0,40,0,.22), 0 1px 1px rgba(0,0,0,.12); }
        .msg-label { display: none; }
        .msg-bubble { white-space: pre-wrap; font-size: 13px; line-height: 1.45; }
        .msg-bubble .msg-code-orb { margin-right: 5px; }
        .msg-media-wrap { display: inline-block; max-width: 100%; vertical-align: top; }
        .msg-bubble .msg-img { max-width: 100%; max-height: none; width: 100%; border-radius: 8px; display: block; cursor: zoom-in; background: #e8eaed; }
        .msg-bubble .msg-video { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; background: #000; }
        .msg-bubble .msg-save-btn { display: block; margin-top: 6px; padding: 5px 12px; font-size: 12px; font-weight: 500; border: 1px solid rgba(0,0,0,.14); border-radius: 10px; background: rgba(255,255,255,.98); color: #1890d9; cursor: pointer; -webkit-tap-highlight-color: transparent; }
        .msg-bubble .msg-save-btn:active { opacity: .88; }
        .msg-row.msg-me .msg-bubble .msg-save-btn { border-color: rgba(0,0,0,.12); background: rgba(255,255,255,.7); color: #166534; }
        .qr-row { display: flex; gap: 12px; margin: 6px 0 14px; flex-wrap: wrap; }
        .qr-btn { display: inline-flex; align-items: center; gap: 8px; padding: 11px 22px; border: 1px solid #cfcfcf; border-radius: 50px; background: #fff; color: #333; font-size: 16px; font-weight: 600; font-family: Arial, Helvetica, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.06); letter-spacing: 0; }
        .qr-btn.is-on { background: #22c55e; border-color: #22c55e; color: #fff; font-weight: 600; }
        .qr-btn:disabled { opacity: 1; cursor: default; }
        .qr-btn .qr-emoji { font-size: 18px; line-height: 1; }
        .msg-qr-hero { display: block; width: calc(100% + 20px); max-width: none; min-height: 160px; margin: -7px -10px 6px; border-radius: 8px 8px 0 0; cursor: zoom-in; background: #e8eaed; }
        .msg-qr-hero.is-ready, .msg-bubble .msg-img.is-ready { min-height: 0; background: transparent; }
        .msg-choice-emoji { font-size: 14px; margin-right: 4px; }
        @media (max-width: 768px) {
            body { font-size: 12px; }
            .chat-wrap { min-height: 100vh; min-height: 100dvh; }
            .chat-header { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
            .chat-footer.chat-footer-normal { padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
        }
        /* 桌面端：嵌入时小窗至少 400px 宽，内容区更宽松；直连打开时使用桌面宽版 */
        @media (min-width: 380px) {
            /* iframe 内父级高度链断裂时 height:100% 会为 0；保留最小高度，且不依赖 max() 以兼容旧内核 */
            .chat-wrap { min-height: 320px; height: 100%; }
            .chat-header { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
            .chat-header-title { font-size: 14px; }
            .chat-body { padding: 10px 10px 8px; }
            .chat-footer.chat-footer-normal { padding: 7px 10px; padding-bottom: max(7px, env(safe-area-inset-bottom)); }
            .chat-footer #input { font-size: 16px; }
        }
        @media (min-width: 769px) {
            .chat-wrap { max-width: 100%; margin: 0; box-shadow: none; border-radius: 0; overflow: hidden; }
        }
        html.visitor-need-phone-boot,
        html.visitor-need-phone-boot body,
        body.visitor-need-phone {
            height: 100%;
            min-height: 100%;
            min-height: 100dvh;
            background: #22c55e;
        }
        body.chat-desktop-standalone {
            background: #d8ebe0;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        html.visitor-need-phone-boot body.chat-desktop-standalone,
        body.visitor-need-phone.chat-desktop-standalone {
            display: flex;
            align-items: center;
            justify-content: center;
            background: #d8ebe0;
        }
        body.chat-desktop-standalone .phone-gate {
            width: 430px;
            height: 820px;
            max-height: calc(100vh - 32px);
            min-height: 0;
            padding: 12px 10px;
            border-radius: 16px;
            overflow: auto;
            background: linear-gradient(180deg, #e2f4e8 0%, #f2faf5 40%, #ffffff 100%);
            box-shadow: 0 18px 50px rgba(0,0,0,.16);
        }
        body.chat-desktop-standalone .phone-gate-stack { max-width: none; flex: 1; display: flex; }
        body.chat-desktop-standalone .chat-wrap {
            width: 390px;
            max-width: 390px;
            height: 780px;
            max-height: calc(100vh - 48px);
            min-height: 0;
            border-radius: 16px;
            box-shadow: 0 18px 50px rgba(0,0,0,.16);
        }
        body.chat-desktop-standalone .chat-header { padding: 8px 12px; }
        body.chat-desktop-standalone .chat-body { padding: 10px 10px 8px; }
        body.chat-desktop-standalone .chat-footer.chat-footer-normal { padding: 8px 10px; }
        body.chat-desktop-standalone .msg-row .msg-bubble { max-width: 84%; }
        html.visitor-need-phone-boot .chat-wrap,
        body.visitor-need-phone .chat-wrap { display: none !important; }
        html.visitor-need-phone-boot .phone-gate { display: flex; }
        .phone-gate { display: none; position: relative; width: 100%; min-height: 100%; min-height: 100dvh; align-items: stretch; justify-content: center; padding: 10px 12px 10px; padding-top: max(var(--card-top, 10px), env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); background: linear-gradient(#22c55e, #22c55e) top / 100% env(safe-area-inset-top) no-repeat, linear-gradient(180deg, #e2f4e8 0%, #f2faf5 28%, #ffffff 100%); }
        body.visitor-need-phone .phone-gate { display: flex; }
        .phone-gate-stack { width: 100%; max-width: 460px; position: relative; flex: 1 1 auto; margin-top: 0; display: flex; flex-direction: column; }
        .phone-lang { display: none !important; }
        form.phone-gate-card { margin: 0; }
        .phone-gate { font-size: 13px; }
        .phone-lang-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid rgba(255,255,255,.95); border-radius: 20px; background: rgba(255,255,255,.72); color: #1c1c1e; box-shadow: 0 2px 10px rgba(22,140,90,.10); font-size: 13px; cursor: pointer; white-space: nowrap; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
        .phone-lang-globe { width: 15px; height: 15px; display: block; flex-shrink: 0; fill: #1fae57; }
        .phone-lang-caret { color: #8e8e93; font-size: 10px; line-height: 1; }
        .phone-lang-menu { display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 128px; padding: 4px 0; background: #fff; border-radius: 12px; box-shadow: 0 10px 32px rgba(0,0,0,.15); overflow: hidden; }
        .phone-lang.open .phone-lang-menu { display: block; }
        .phone-lang-item { display: block; width: 100%; border: 0; background: transparent; padding: 8px 14px; text-align: left; font-size: 12px; font-family: inherit; color: #333; cursor: pointer; line-height: 1.35; }
        .phone-lang-item:hover { background: #f2f8f4; }
        .phone-lang-item.is-active { color: #16a34a; font-weight: 700; }
        .phone-gate-card { width: 100%; flex: 1 1 auto; background: #fff; border-radius: 18px; box-shadow: 0 6px 24px rgba(16, 90, 60, .08); padding: 28px 22px 24px; position: relative; display: flex; flex-direction: column; }
        .phone-gate-wm { position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%); width: 46%; opacity: .05; pointer-events: none; z-index: 0; }
        .phone-gate-wm svg { width: 100%; height: auto; display: block; }
        .phone-gate-card > *:not(.phone-gate-wm):not(.phone-gate-dot) { position: relative; z-index: 1; }
        .phone-gate-card > .phone-gate-country:not(.phone-gate-wm) { z-index: 4; }
        .phone-gate-card > .phone-gate-country.open { z-index: 50; }
        .phone-gate-head { display: flex; align-items: center; gap: 14px; padding-right: 22px; }
        .phone-gate-logo { width: 72px; height: 72px; border-radius: 18px; object-fit: cover; background: #111; flex-shrink: 0; }
        .phone-gate-logo-fallback { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; font-weight: 700; letter-spacing: .02em; }
        .phone-gate-titles { min-width: 0; }
        .phone-gate-title { font-size: 22px; font-weight: 700; color: #0b0b0c; line-height: 1.2; }
        .phone-gate-sub { font-size: 13px; color: #8e8e93; margin-top: 4px; }
        .phone-gate-dot { width: 12px; height: 12px; border-radius: 50%; background: #25d366; position: absolute; right: 18px; top: 18px; z-index: 2; box-shadow: 0 0 0 4px rgba(37, 211, 102, .16); pointer-events: none; }
        .phone-gate-lead { font-size: 15px; color: #1c1c1e; margin: 18px 0 6px; line-height: 1.5; font-weight: 400; }
        .phone-gate-hint { font-size: 13px; color: #8e8e93; margin: 0 0 14px; }
        .phone-gate-country { position: relative; }
        .phone-gate-country-btn { position: relative; width: 100%; border: 1px solid #d9dee3; border-radius: 12px; background: #fff; padding: 12px 14px; color: #0b0b0c; display: flex; align-items: center; gap: 8px; cursor: pointer; text-align: left; font-size: 15px; }
        .phone-gate-country-btn:active { background: #f6faf7; }
        .phone-gate-country-nm { font-size: 13px; color: #0b0b0c; }
        .phone-gate-country-paren { font-size: 12px; color: #8e8e93; }
        .phone-gate-country-caret { margin-left: auto; color: #9aa0a6; font-size: 12px; line-height: 1; }
        .phone-gate-flag-img { width: 22px; height: 15px; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.06); flex-shrink: 0; }
        .phone-gate-country-panel { display: none; position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid #e4e7ea; border-radius: 12px; box-shadow: 0 12px 34px rgba(0,0,0,.15); z-index: 50; overflow: hidden; }
        .phone-gate-country.open .phone-gate-country-panel { display: block; }
        .phone-gate-country-search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid #f0f2f4; }
        .phone-gate-country-search .phone-gate-mag { flex-shrink: 0; font-size: 13px; line-height: 1; }
        .phone-gate-country-search input { flex: 1; min-width: 0; border: 0; outline: none; padding: 11px 0; font-size: 13px; color: #222; background: transparent; }
        .phone-gate-country-search input::placeholder { color: #c0c4c8; }
        .phone-gate-country-clear { border: 0; background: transparent; color: #b9c0c8; font-size: 15px; line-height: 1; padding: 0 2px; cursor: pointer; flex-shrink: 0; }
        .phone-gate-country-list { max-height: 250px; overflow-y: auto; }
        .phone-gate-country-item { width: 100%; border: 0; background: #fff; padding: 10px 12px; display: flex; align-items: center; gap: 9px; font-size: 13px; color: #333; cursor: pointer; text-align: left; }
        .phone-gate-country-item-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .phone-gate-country-item-dial { color: #8b96a0; flex-shrink: 0; }
        .phone-gate-country-item:hover { background: #f4f6f8; }
        .phone-gate-country-item.is-active { background: #f0fbf4; }
        .phone-gate-country-item.is-active .phone-gate-country-item-name,
        .phone-gate-country-item.is-active .phone-gate-country-item-dial { color: #22c55e; font-weight: 700; }
        .phone-gate-country-empty { padding: 14px; text-align: center; color: #b9c0c8; font-size: 12px; }
        .phone-gate-number-wrap { display: flex; align-items: stretch; margin-top: 12px; border: 1px solid #d9dee3; border-radius: 12px; background: #fff; }
        .phone-gate-country-btn:focus, .phone-gate-number-wrap:focus-within { border-color: #25d366; box-shadow: 0 0 0 3px rgba(37, 211, 102, .12); outline: none; }
        .phone-gate-prefix { flex: none; width: 68px; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600; color: #0b0b0c; white-space: nowrap; }
        .phone-gate-sep { width: 1px; background: #e2e6ea; margin: 8px 0; flex-shrink: 0; }
        .phone-gate-number { flex: 1; min-width: 0; border: 0; border-radius: 0; padding: 12px 14px; font-size: 16px; color: #0b0b0c; outline: none; background: transparent; }
        .phone-gate-number::placeholder { color: #c0c4c8; font-size: 14px; }
        .phone-gate-agree { font-size: 13px; color: #8e8e93; margin: 18px 2px 16px; line-height: 1.5; }
        .phone-gate-agree .phone-gate-link { color: #3478f6; text-decoration: none; }
        .phone-gate-error { display: none; color: #e02424; font-size: 12px; line-height: 1.45; margin: 6px 2px 0; }
        .phone-gate-btn { display: block; width: 100%; border: none; border-radius: 12px; background: #22c55e; color: #fff; font-size: 16px; font-weight: 600; padding: 13px 0; cursor: pointer; box-shadow: 0 4px 14px rgba(34, 197, 94, .35); margin-top: auto; }
        .phone-gate-btn:active { background: #16a34a; }
        .phone-gate-foot { display: flex; align-items: flex-start; gap: 8px; margin: 18px 0 0; }
        .phone-gate-foot-dot { width: 7px; height: 7px; border-radius: 50%; background: #007aff; margin-top: 6px; flex-shrink: 0; }
        .phone-gate-foot span:last-child { font-size: 11px; color: #3a3a3c; line-height: 1.55; }
        @media (max-width: 820px) {
            .phone-gate { padding: 10px 10px; padding-top: max(var(--card-top, 10px), env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
            .phone-gate-card { padding: 24px 16px 18px; border-radius: 16px; }
        }
        /* 号码页输入保持 16px，避免 iOS 聚焦放大；聊天输入框已单独设为 14px */
        .phone-gate input, .phone-gate textarea, .phone-gate select { font-size: 16px; }
        .phone-gate-number::placeholder { font-size: 14px; }
    